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

Question: Initial Solutions #100

Closed AndreasH96 closed 5 months ago

AndreasH96 commented 3 years ago

Hi, First of all, thank you for a great tool. I have one question about the status of the generation of initial solutions; I'm using your tool to solve a Multi-Depot VRP. I'm currently using a simple "cheapest-arc"-ish initial solution. I saw that in https://jmetal.readthedocs.io/en/latest/autoconfiguration.html there is a parameter called createInitialSolutions in the NSGA-II. It seems like this is only the case for the java version. What is the status of initial solutions for python?

Best Regards

llyhec commented 3 years ago

Is there any progress with this inquiry: is it possible to set the initial population?

Thank you.

AndreasH96 commented 3 years ago

Hi,

I'm using jMetalPy to solve the VRP (meaning that I'm using PermutationSolutions). I have implemented a version of the Cheapest Insertion algorithm, and I'm currently using it as my initial solution. First, I run the Cheapest Insertion algorithm to get an initial solution. Then I set the variables field to this solution in create_solution. So, to set the initial solution, one has to create either extend the Problem class used or change its create_solution function to set the solution variables.

I hope this helps!

CryoARIUM commented 2 years ago

Could you please show any examples that how to extend the problem class or create_solution function in order to use your own initial solution ? @AndreasH96

AndreasH96 commented 2 years ago

Could you please show any examples that how to extend the problem class or create_solution function in order to use your own initial solution ? @AndreasH96

Hi @CryoARIUM , I was extending the PermutationProblem class, here is a minimalistic example of how I did it. It was a while since I did this but I hope this solves your problem? I stored parameters in a dictionary called problemData and passed it to the customized class.

class VRP(PermutationProblem):

    def __init__(self,problemData):
        super(VRP,self).__init__()

        self.object_directions=[self.MINIMIZE,self.MINIMIZE]
        self.number_of_objectives = problemData['objective_amount']
        self.objective_labels = problemData['objective_labels']
        self.number_of_constraints = problemData['constraint_amount']
        self.number_of_variables = problemData['number_of_cities']

    def create_solution(self) -> PermutationSolution:
        new_solution = PermutationSolution(number_of_variables=self.number_of_variables,
                                           number_of_objectives=self.number_of_objectives,
                                           number_of_constraints=self.number_of_constraints)        

        new_solution.variables = customInitialSolution(<input>)

        return new_solution
CryoARIUM commented 2 years ago

@AndreasH96 Thank you for your reply ! I would like to use my own initial solutions. Your code help me to extend problem class. I will try my own problem with my initial solutions.