Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending MOEA with a simulation #157

Closed
Onnene opened this issue Feb 27, 2018 · 3 comments
Closed

Extending MOEA with a simulation #157

Onnene opened this issue Feb 27, 2018 · 3 comments
Labels

Comments

@Onnene
Copy link

Onnene commented Feb 27, 2018

Hi @dhadka,

I want to know if MOEA can be extended in such a way that a simulation model is used as the evaluation component within the framework. For example, if a GA is to be used as the solution algorithm, after initializing the first population, rather than evaluate the individuals with objective functions to get their determine their fitness, can a simulation rather be plugged in and utilized as the evaluation module after which the population is scored and control returns back to the GA for the reproduction process? Assuming the above example is not feasible can you describe how such an integration (MOEA with a simulation) might work.

Regards

@dhadka
Copy link
Member

dhadka commented Feb 27, 2018

Yes, when you create a problem (by implementing the Problem interface or extending AbstractProblem), you will need to define an public void evaluate(Solution solution) method. Inside this method is where you would call your simulation model with the decision variables and read the objectives and constraints back out.

How you implement this method depends on how your simulation model takes its inputs and writes its outputs. For example, suppose your simulation model uses an input file and produces an output file with the objectives. Your evaluate method would look like:

public void evaluate(Solution solution) {
    double[] vars = EncodingUtils.getReal(solution); // Assuming your decision variables are all reals

    // Generate the input file with these variables
    File file = new File("input.txt");
    ... create the input file ...

    // Call your simulation model (if the model procures a lot of output, redirect the output stream to stdout)
    Process p = Runtime.getRuntime().exec(new String[] { "mySimulation.exe", "-i", "input.txt", "-o", "output.txt" });
    p.waitFor();

    // Read the output file
    File file = new File("output.txt");
    ... read the contents of the file ...

    solution.setObjectives(...);
    solution.setConstraints(...);
}

Also take a look at Example5: http://moeaframework.org/examples.html#example5. This demonstrates the ExternalProblem class, which provides a simple mechanism to pass inputs to and read the outputs from a program.

@Onnene
Copy link
Author

Onnene commented Feb 27, 2018

Thank you very much!

@github-actions
Copy link

This is an automated message. This issue is flagged as stale and will be closed in 7 days. If you feel this issue is still relevant, leave a comment to keep the issue open. Please also consider contributing a fix for the issue.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants