jMetal / jMetalPy

A framework for single/multi-objective optimization with metaheuristics
https://jmetal.github.io/jMetalPy/index.html
MIT License
498 stars 150 forks source link

constraint programming #89

Closed maamani10 closed 1 year ago

maamani10 commented 3 years ago

hi and tnx for great project. can u explain if our model have multiple constraint and objective function how we can implement it and use Jmetalpy?

AndreasH96 commented 3 years ago

Hi,

I don't know if this will be helpful but I'm currently using JmetalPy for my masters project. I'm solving a vehicle routing problem and I'm implementing the constraints through simply increasing the cost with a large value if the constraint is not met. This makes the algorithm deny the solution. I guess this is somewhat of a workaround but it seems to work for now.

Here is an example, I have a list of lists named paths and I've got a set of nodes callet permutation. This constraint checks so that all the nodes are visited by some path.

if not self.__allVisited(permutation,paths):
       fitness += 10e10 

solution.objectives[0]  = fitness

In my case I want to minimize the cost, if you would want to maximize a fitness value I guess you could subtract a large number instead.

If someone has a better solution for this I would appreciate it, but this seems to be working for now as I said.

ajnebro commented 3 years ago

The constraing handling mechanism used in jMetalPy is the same used in jMetal, which is described here: https://jmetal.readthedocs.io/en/latest/constraints.html

AndreasH96 commented 3 years ago

Thank you @ajnebro !