Skip to content

Commit

Permalink
Update to version 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed May 27, 2024
1 parent e006852 commit dd7c335
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 244 deletions.
6 changes: 3 additions & 3 deletions moeaframework.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ org.moeaframework.analysis.diagnostics.problems = GAA, HBV, \
## randomly.
#matlab.port = 20001

## Time to wait, in milliseconds, after launching Matlab before attempting to
## establish a connection. We found 30 seconds works well.
#matlab.sleep = 30000
## The number of retries, each delayed by 1 second, spent trying to establish
## the connection
#matlab.retries = 30
20 changes: 14 additions & 6 deletions native/shared/moeaframework.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
#endif

#define MOEA_WHITESPACE " \t"
#define MOEA_BUFFER_SIZE 1024

#ifndef MOEA_BUFFER_SIZE
#define MOEA_BUFFER_SIZE 4096
#endif

FILE* MOEA_Stream_input = NULL;
FILE* MOEA_Stream_output = NULL;
Expand Down Expand Up @@ -112,7 +115,7 @@ MOEA_Status MOEA_Error(const MOEA_Status status) {
}
}

MOEA_Status MOEA_Buffer_capacity(int required) {
MOEA_Status MOEA_Buffer_capacity(size_t required) {
if (required < MOEA_Buffer_limit) {
return MOEA_SUCCESS;
}
Expand Down Expand Up @@ -168,7 +171,7 @@ MOEA_Status MOEA_Init(const int objectives, const int constraints) {
MOEA_Status MOEA_Init_socket(const int objectives, const int constraints, const char* service) {
int gai_errno;
SOCKET listen_sock;
int yes = 1;
const int yes = 1;
struct addrinfo hints;
struct addrinfo *servinfo = NULL;
struct addrinfo *sp = NULL;
Expand Down Expand Up @@ -253,15 +256,15 @@ MOEA_Status MOEA_Debug(const char* format, ...) {

MOEA_Status MOEA_Next_solution() {
size_t len = 0;
int character;

MOEA_Buffer_position = 0;

if (MOEA_Buffer_limit > 0) {
MOEA_Buffer[0] = '\0';
}

while (!feof(MOEA_Stream_input)) {
/* loop until the full line is read or end of file */
while (1) {
/* expand buffer if required */
if (MOEA_Buffer_capacity(MOEA_Buffer_position + MOEA_BUFFER_SIZE) != MOEA_SUCCESS) {
return MOEA_Error(MOEA_MALLOC_ERROR);
Expand Down Expand Up @@ -289,7 +292,8 @@ MOEA_Status MOEA_Next_solution() {
MOEA_Buffer[MOEA_Buffer_position] = '\0';
}

if (MOEA_Buffer[MOEA_Buffer_position-1] == '\n') {
/* exit loop when no data read or newline found */
if (MOEA_Buffer_position == 0 || MOEA_Buffer[MOEA_Buffer_position-1] == '\n') {
break;
}
}
Expand Down Expand Up @@ -627,6 +631,10 @@ MOEA_Status MOEA_Terminate() {
WSACleanup();
#endif

if (MOEA_Buffer != NULL) {
free(MOEA_Buffer);
}

return MOEA_SUCCESS;
}

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>org.moeaframework</groupId>
<artifactId>moeaframework</artifactId>
<version>4.1</version>
<version>4.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/moeaframework/benchmarks/HBV.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@

import java.io.File;

import org.apache.commons.lang3.SystemUtils;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.RealVariable;
import org.moeaframework.problem.NativeCommand;
import org.moeaframework.problem.NativeProblem;
import org.moeaframework.problem.ExternalProblem;

public class HBV extends NativeProblem {
public class HBV extends ExternalProblem {

public static final double[] EPSILON = new double[] {
0.01, 0.025, 0.01, 0.01
};

public static final NativeCommand COMMAND = new NativeCommand("hbv",
new String[] { },
new File("./native/HBV/bin/"));

public HBV() {
super(COMMAND);
super(new Builder()
.withCommand(SystemUtils.IS_OS_WINDOWS ? "hbv.exe" : "hbv")
.withWorkingDirectory(new File("./native/HBV/bin/")));
}

@Override
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/moeaframework/benchmarks/LRGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,21 @@

import java.io.File;

import org.apache.commons.lang3.SystemUtils;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.RealVariable;
import org.moeaframework.problem.NativeCommand;
import org.moeaframework.problem.NativeProblem;
import org.moeaframework.problem.ExternalProblem;

public class LRGV extends NativeProblem {
public class LRGV extends ExternalProblem {

public static final double[] EPSILON = {
0.0009, 0.002, 0.03, 0.004, 0.004
};

public static final NativeCommand COMMAND = new NativeCommand("lrgv",
new String[] { "-m", "std-io", "-b", "AllDecAll", "-c", "ten-year" },
new File("./native/LRGV/bin/"));

public LRGV() {
super(COMMAND);
super(new Builder()
.withCommand(SystemUtils.IS_OS_WINDOWS ? "lrgv.exe" : "lrgv", "-m", "std-io", "-b", "AllDecAll", "-c", "ten-year")
.withWorkingDirectory(new File("./native/LRGV/bin/")));
}

@Override
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/moeaframework/benchmarks/LakeProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,21 @@

import java.io.File;

import org.apache.commons.lang3.SystemUtils;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.RealVariable;
import org.moeaframework.problem.NativeCommand;
import org.moeaframework.problem.NativeProblem;
import org.moeaframework.problem.ExternalProblem;

public class LakeProblem extends NativeProblem {
public class LakeProblem extends ExternalProblem {

public static final double[] EPSILON = {
0.01, 0.01, 0.0001, 0.0001
};

public static final NativeCommand COMMAND = new NativeCommand("lake",
new String[] { },
new File("./native/LakeProblem/bin/"));

public LakeProblem() {
super(COMMAND);
super(new Builder()
.withCommand(SystemUtils.IS_OS_WINDOWS ? "lake.exe" : "lake")
.withWorkingDirectory(new File("./native/LakeProblem/bin/")));
}

@Override
Expand Down
42 changes: 14 additions & 28 deletions src/main/java/org/moeaframework/benchmarks/Radar.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,35 @@
package org.moeaframework.benchmarks;

import java.io.File;
import java.time.Duration;

import org.moeaframework.core.FrameworkException;
import org.moeaframework.core.PRNG;
import org.moeaframework.core.Settings;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.RealVariable;
import org.moeaframework.problem.ExternalProblem;
import org.moeaframework.problem.NativeCommand;
import org.moeaframework.util.io.RedirectStream;

public class Radar extends ExternalProblem {

public static final String PATH = "./native/Radar/bin/";

public Radar() throws Exception {
super("127.0.0.1", startProcess());
super(createBuilder());
}

public static int startProcess() throws Exception {
validate();

int port = Settings.PROPERTIES.getInt("matlab.port",
PRNG.nextInt(10000, 65536));

NativeCommand command = new NativeCommand(
Settings.PROPERTIES.getString("matlab.path", "matlab"),
new String[] { "-batch", "startEval(8,9,0,'radar','" + port + "')" },
new File(PATH));

Process process = command.exec();

RedirectStream.redirect(process.getInputStream(), System.out);
RedirectStream.redirect(process.getErrorStream(), System.err);

Thread.sleep(Settings.PROPERTIES.getInt("matlab.sleep", 30000));

return port;
}

public static void validate() {
if (!new File(PATH, "testpris.p").exists()) {
public static Builder createBuilder() {
if (!new File("./native/Radar/bin/", "testpris.p").exists()) {
throw new FrameworkException("testpris.p missing, see installation instructions");
}

int port = Settings.PROPERTIES.getInt("matlab.port", PRNG.nextInt(10000, 65536));
int retries = Settings.PROPERTIES.getInt("matlab.retries", 30);
String command = Settings.PROPERTIES.getString("matlab.path", "matlab");

return new Builder()
.withCommand(command, "-batch", "startEval(8,9,0,'radar','" + port + "')")
.withWorkingDirectory(new File("./native/Radar/bin/"))
.withSocket("127.0.0.1", port)
.withRetries(retries, Duration.ofSeconds(1));
}

@Override
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/moeaframework/benchmarks/WDS.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

import java.io.File;

import org.apache.commons.lang3.SystemUtils;
import org.moeaframework.core.Solution;
import org.moeaframework.core.variable.EncodingUtils;
import org.moeaframework.problem.NativeCommand;
import org.moeaframework.problem.NativeProblem;
import org.moeaframework.problem.ExternalProblem;

/**
* The water distribution system (WDS) problem.
*
* See https://engineering.exeter.ac.uk/research/cws/resources/benchmarks/pareto/ for more details.
*/
public class WDS extends NativeProblem {
public class WDS extends ExternalProblem {

public enum WDSInstance {

Expand Down Expand Up @@ -88,16 +88,18 @@ public double[] getEpsilon() {
return epsilon.clone();
}

public NativeCommand getCommand() {
return new NativeCommand(getName(), new String[] { }, new File("./native/WDS/bin/"));
public Builder getBuilder() {
return new Builder()
.withCommand(SystemUtils.IS_OS_WINDOWS ? getName() + ".exe" : getName())
.withWorkingDirectory(new File("./native/WDS/bin/"));
}

}

private final WDSInstance instance;

public WDS(WDSInstance instance) {
super(instance.getCommand());
super(instance.getBuilder());
this.instance = instance;
}

Expand Down
85 changes: 0 additions & 85 deletions src/main/java/org/moeaframework/problem/NativeCommand.java

This file was deleted.

Loading

0 comments on commit dd7c335

Please sign in to comment.