def test_case_3(self): # prepare raw problem variables = [0, 1, 2, 3] objectives = [{0: -10, 1: -5, 2: -1, 3: -5}, {0: 3, 1: 2, 2: 3, 3: 0}] constraints = dict() # prepare solvers for solver_name in self.binary_solver: if solver_name == 'epsilon': problem = NextReleaseProblem.MOIP( \ variables, objectives, constraints, \ dict(), dict() \ ) else: constraints = JNRP.regularize_constraints( constraints, len(variables)) problem = JNRP(variables, objectives, constraints) solver = Solver(solver_name) # prepare and solve solver.load(problem) solver.execute() # get the solutions solutions = solver.solutions() print(solver_name + '\t\t' + str(len(solutions))) self.display(solutions, 5)
def test_case_2(self): # prepare raw problem variables = [0, 1, 2, 3] objectives = [{0: -10, 1: -5, 2: -1, 3: 5}] constraints = [{2: 1, 4: 0}, {0: 1, 3: -1, 4: 0}] # prepare solvers for solver_name in self.single_solver: if solver_name == 'single': problem = NextReleaseProblem.MOIP( \ variables, objectives, constraints, \ ['L' for _ in range(len(constraints))], dict() \ ) else: constraints = JNRP.regularize_constraints( constraints, len(variables)) problem = JNRP(variables, objectives, constraints) solver = Solver(solver_name) # prepare and solve solver.load(problem) solver.execute() # get the solutions solutions = solver.solutions() print(solver_name + '\t\t' + str(len(solutions))) self.display(solutions, 5)
def __to_bi_general_form(self) -> ProblemType: # only for classic and realistic assert self.__project.startswith('classic') or self.__project.startswith('realistic') # requirement dependencies should be eliminated assert not self.__dependencies # modelling variables, objectives, inequations, inequations_operators, equations = \ self.__basic_bi_form() # construct Problem if self.__problem_type == 'default': return NextReleaseProblem.MOIP(variables, objectives, inequations, inequations_operators, equations) elif self.__problem_type == 'jmetal': file_name = self.__project + '_' + 'binary.json' NextReleaseProblem.dump(file_name, variables, objectives, inequations) return JNRP(variables, objectives, inequations) else: assert False
def __to_tri_max_customers_form(self) -> ProblemType: # only for classic and realistic assert self.__project.startswith('classic') or self.__project.startswith('realistic') # requirement dependencies should be eliminated assert not self.__dependencies # modelling with bi-objective variables, objectives, inequations, inequations_operators, equations = \ self.__basic_bi_form() # add the third objective, max customers <=> min -customers max_customers = {k:-1 for k in self.__profit} objectives.append(max_customers) # construct Problem if self.__problem_type == 'default': return NextReleaseProblem.MOIP(variables, objectives, inequations, inequations_operators, equations) elif self.__problem_type == 'jmetal': file_name = self.__project + '_' + 'tricus.json' NextReleaseProblem.dump(file_name, variables, objectives, inequations) return JNRP(variables, objectives, inequations) else: assert False
def __to_bicst_form(self, max_cost : Union[int, float] = None, \ min_profit : Union[int, float] = None, \ min_requirements : int = None, \ min_customers : int = None\ ) -> ProblemType: # only for classic and realistic assert self.__project.startswith('classic') or self.__project.startswith('realistic') # requirement dependencies should be eliminated assert not self.__dependencies # modelling variables, objectives, inequations, inequations_operators, equations = \ self.__basic_bi_form() # add additional constraints constant_id = len(variables) if max_cost: # sum cost <= max_cost inequation = {k:v for k, v in self.__cost.items()} if isinstance(max_cost, int): inequation[constant_id] = max_cost else: print('max cost: ', ceil(max_cost*sum(list(self.__cost.values())))) inequation[constant_id] = ceil(max_cost*sum(list(self.__cost.values()))) inequations.append(inequation) inequations_operators.append('L') if min_profit: # sum profit >= min_profit # -p1 -p2 - ... <= - min_profit inequation = {k:-v for k, v in self.__profit.items()} if isinstance(min_profit, int): inequation[constant_id] = - min_profit else: print('min profit: ', floor(min_profit*sum(list(self.__profit.values())))) inequation[constant_id] = - floor(min_profit*sum(list(self.__profit.values()))) inequations.append(inequation) inequations_operators.append('L') if min_requirements: # |requirements| >= min_requirements inequation = {k:-1 for k in self.__cost} if isinstance(min_requirements, int): inequation[constant_id] = - min_requirements else: print('min requirements: ', floor(min_requirements*len(self.__cost))) inequation[constant_id] = - floor(min_requirements*len(self.__cost)) inequations.append(inequation) inequations_operators.append('L') if min_customers: # |customers| >= min_customers inequation = {k:-1 for k in self.__profit} if isinstance(min_customers, int): inequation[constant_id] = - min_customers else: print('min customers: ', floor(min_customers*len(self.__profit))) inequation[constant_id] = - floor(min_customers*len(self.__profit)) inequations.append(inequation) inequations_operators.append('L') # construct Problem if self.__problem_type == 'default': return NextReleaseProblem.MOIP(variables, objectives, inequations, inequations_operators, equations) elif self.__problem_type == 'jmetal': file_name = self.__project + '_' + 'bicst.json' NextReleaseProblem.dump(file_name, variables, objectives, inequations) return JNRP(variables, objectives, inequations) else: assert False