Project-Platypus / Platypus

A Free and Open Source Python Library for Multiobjective Optimization
GNU General Public License v3.0
563 stars 153 forks source link

How to return a global optimum #127

Closed michelesaputo closed 1 year ago

michelesaputo commented 4 years ago

Hi, as I'm trying to get more and more into coding i was interested into use platypuc for multiple response optimization in order to find a global optimum given a set of n>2 equations and constraint.

I tried to do that with simple equation but i didn't have any luck. Any suggestion about the algorithm to be used or the code line to be used?

here's the piece of code without any tweaks

MRO_rev1 - Copia.txt

Thank you, Michele

mronda commented 4 years ago

Hi Michele, You need to define the constraints in your problem. Follow this example for instance and notice the return statement containing two constraints:

from platypus import NSGAII, Problem, Real

def belegundu(vars):
    x = vars[0]
    y = vars[1]
    return [-2*x + y, 2*x + y], [-x + y - 1, x + y - 7]

problem = Problem(2, 2, 2)
problem.types[:] = [Real(0, 5), Real(0, 3)]
problem.constraints[:] = "<=0"
problem.function = belegundu

algorithm = NSGAII(problem)
algorithm.run(10000)

And to get the most optimal point you can query your result for smallest or largest objective score. Kinda of like this: objectives = [s.objectives[:] for s in result]

For algorithms you can compare using the experimenter to see what kind of results you get. Hope that helps.

michelesaputo commented 4 years ago

Hi, that's a good hint, thank you. as I wrote some other code i noticed that if i write the code like this

from platypus import NSGAII, Problem, Real

def belegundu(vars): x = vars[0] y = vars[1] return [-2x + y, 2x + y], [-x + y - 1, x + y - 7]

problem = Problem(2, 2, 2) problem.types[:] = [Real(0, 5), Real(0, 3)] problem.constraints[:] = "<=0" problem.function = belegundu

algorithm = NSGAII(problem) algorithm.run(10000) objectives1 = [solution.objectives[0] for solution in algorithm.result] objectives2 = [solution.objectives[1] for solution in algorithm.result] print(len(objectives1)) print(objectives1) print(len(objectives2)) print(objectives2)

arrays objectives1 and objectives2 consist of 100 elements regardless of the number of runs. how can i increase the number of runs, if there's a way to do so?

Thank you, Michele

Il giorno gio 6 feb 2020 alle ore 22:30 mronda notifications@github.com ha scritto:

Hi Michele, You need to define the constraints in your problem. Follow this example for instance and notice the return statement containing two constraints:

from platypus import NSGAII, Problem, Real

def belegundu(vars): x = vars[0] y = vars[1] return [-2x + y, 2x + y], [-x + y - 1, x + y - 7]

problem = Problem(2, 2, 2) problem.types[:] = [Real(0, 5), Real(0, 3)] problem.constraints[:] = "<=0" problem.function = belegundu

algorithm = NSGAII(problem) algorithm.run(10000)

And to get the most optimal point you can query your result for smallest or largest objective score. Kinda of like this: objectives = [s.objectives[:] for s in result]

For algorithms you can compare using the experimenter to see what kind of results you get. Hope that helps.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Project-Platypus/Platypus/issues/127?email_source=notifications&email_token=AOOO47KDAWJ7SDQML2E4MDTRBR6ODA5CNFSM4KPHPYY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELA3JSA#issuecomment-583120072, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOOO47IRB5SYQGSCXZJNZNLRBR6ODANCNFSM4KPHPYYQ .

dhadka commented 4 years ago

You are seeing 100 results since the population_size argument is 100 by default. You can increase this with NSGAII(problem, population_size=250) for example.

michelesaputo commented 4 years ago

Thank you for the response, i don't understand exactly whic are the differences in

algorithm = NSGAII(problem,population_size=250)

algorithm.run(1000)

is that 250 a number of evaluation randomly picked after the algorithm completion or the meaning is different?

Thank you for you patience, Michele

Il giorno gio 13 feb 2020 alle ore 17:25 David Hadka < notifications@github.com> ha scritto:

You are seeing 100 results since the population_size argument is 100 by default. You can increase this with NSGAII(problem, population_size=250) for example.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Project-Platypus/Platypus/issues/127?email_source=notifications&email_token=AOOO47I6VREBNIVLL2OODXDRCVX6ZA5CNFSM4KPHPYY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELVUKPQ#issuecomment-585844030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOOO47PICPUMM3LYCWBJLD3RCVX6ZANCNFSM4KPHPYYQ .

mronda commented 4 years ago

Hi Michele, The algo.run(n) is the number of function evaluations. So if your population is 250 and you run algo.run(condition=250) it will just evaluate those individuals without mutation/crossover. You can check the TerminationConditions to see how that works. Hope that helps.

github-actions[bot] commented 1 year ago

This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR.