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
Experimenter using own problem #145
Comments
I am having the same problem. |
Sorry I have not yet received a reply. |
What error message are you getting? |
solution.variables = [x.rand() for x in problem.types] My question is how to set out the code for using your own problem in the experimenter generator rather than a predefined problem such as DTLZ2 or Belegundu.
|
I think the issue is that you are redefining the problem on this line:
I.e. the problem here is not the same I think you need to use the reference/variable to the problem you have setup at the start of the script, and pass that to N = 2
problem = Problem(multiple_days_assigned_size, 2, 2)
problem.directions[1] = Problem.MINIMIZE
problem.directions[0] = Problem.MAXIMIZE
problem.constraints[:] = ">=0"
problem.types[:] = Integer(0, my_counter_again - 1)
problem.function = lambda x: evaluation_function2(x, jobs, c_time_added_up, total_allowed_time_all_jobs, extra_time)
# calculate the difference in models nsga2 and nsga3
if __name__ == "__main__":
algorithms = [NSGAII, (NSGAIII, {"divisions_outer":12})]
# run the experiment
results = experiment(algorithms, [problem], nfe=10000, seeds=10) `
# calculate the hypervolume indicator between two algorithms
hyp = Hypervolume(minimum=[min_pri, min_cost], maximum=[max_pri, max_cost])
hyp_result = calculate(results, hyp) display(hyp_result, ndigits=3) PS if you put your code between three back-ticks it'll format correctly and be easier to read. See: https://guides.github.com/features/mastering-markdown/ |
Hi Jetuk, thanks for your help! I achieved to get passed the Here's my code: # Custom experimenter
from platypus import *
problem = Problem(2, 2)
problem.types[0:] = Permutation(range(len(carbon_bus)))
problem.types[1:] = Binary(len(carbon_bus))
problem.directions[:] = Problem.MINIMIZE
problem.function = two_opt
if __name__ == "__main__":
algorithms = [NSGAII(problem,variator=PMX()), (NSGAIII, {"divisions_outer":12})]
# run the experiment
results = experiment(algorithms, problem, seeds=5, nfe=1000)
# calculate the hypervolume indicator
#hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
#hyp_result = calculate(results, hyp)
#display(hyp_result, ndigits=3) I am working on a bi-objective TSP. |
Can you paste the full traceback? |
Sure, sorry for the confusion! ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-91-4e87550fe452> in <module>
12
13 # run the experiment
---> 14 results = experiment(algorithms, problem, seeds=5, nfe=1000)
15
16 # calculate the hypervolume indicator
c:\users\kevin\appdata\local\programs\python\python37\lib\site-packages\platypus\experimenter.py in experiment(algorithms, problems, seeds, nfe, evaluator, display_stats)
179 evaluator = PlatypusConfig.default_evaluator
180
--> 181 job_results = evaluator.evaluate_all(generator)
182
183 # convert results to structured format
c:\users\kevin\appdata\local\programs\python\python37\lib\site-packages\platypus\evaluator.py in evaluate_all(self, jobs, **kwargs)
86
87 if log_frequency is None:
---> 88 return list(self.map_func(run_job, jobs))
89 else:
90 result = []
c:\users\kevin\appdata\local\programs\python\python37\lib\site-packages\platypus\experimenter.py in evaluate_job_generator(algorithms, problems, seeds, nfe, display_stats)
89 else:
90 algorithm = algorithms[i]
---> 91 algorithm_name = algorithm.__name__
92 kwargs = {}
93
AttributeError: 'NSGAII' object has no attribute '__name__' |
I think the experimenter is expecting algorithm classes, not instances. Try this: # Custom experimenter
from platypus import *
problem = Problem(2, 2)
problem.types[0:] = Permutation(range(len(carbon_bus)))
problem.types[1:] = Binary(len(carbon_bus))
problem.directions[:] = Problem.MINIMIZE
problem.function = two_opt
if __name__ == "__main__":
algorithms = [(NSGAII, {"variator": PMX()}), (NSGAIII, {"divisions_outer":12})]
# run the experiment
results = experiment(algorithms, problem, seeds=5, nfe=1000)
# calculate the hypervolume indicator
#hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
#hyp_result = calculate(results, hyp)
#display(hyp_result, ndigits=3) |
Hi there, Thank you for your help. I think the new code worked however I got the issue: raise PlatypusError("NSGAIII currently only works with minimization problems") Do any of the other GAs work with maximization problems or is it just NSGAII? Cheers, Sabrina |
I am not sure, you'll have to check the code. A work around is to use minimisation and return the negative of the value for objectives you wish to maximise. |
Thanks the code works for minimisation. However when I try and run the code using the evaluator it hasn't finished, even though the code has been running for three hours now:
|
Hi there,
I was just wondering how to use the experimenter using ones own problem rather than a predefined problem?
Run the algorithm
N = 2000
problem = Problem(multiple_days_assigned_size, 2, 2)
problem.directions[1] = Problem.MINIMIZE
problem.directions[0] = Problem.MAXIMIZE
problem.constraints[:] = ">=0"
problem.types[:] = Integer(0, my_counter_again - 1)
problem.function = lambda x: evaluation_function2(x, jobs, c_time_added_up, total_allowed_time_all_jobs,
extra_time)
algorithm = NSGAII(problem)
algorithm.run(N)
feasible_solutions_total = [s for s in algorithm.result if s.feasible]
Nondominated_solutions_total = nondominated(algorithm.result)
calculate the difference in models nsga2 and nsga3
if name == "main":
algorithms = [NSGAII, (NSGAIII, {"divisions_outer":12})]
problems = [Problem(multiple_days_assigned_size, 2, 2)] #what would I put in here?
Any tips would be greatly appreciated!
Thanks
The text was updated successfully, but these errors were encountered: