moead_framework.problem.combinatorial.knapsack.KnapsackProblem

class moead_framework.problem.combinatorial.knapsack.KnapsackProblem(number_of_objective, instance_file=None, weights=None, profits=None, capacities=None)[source]

Bases: moead_framework.problem.problem.Problem

Implementation of the Multiobjective knapsack problem by Thibaut Lust. The problem is compatible with files available on the author website: http://www-desir.lip6.fr/~lustt/Research.html#MOKP

Example:

>>> from moead_framework.problem.combinatorial import KnapsackProblem
>>>
>>> instance_file = "moead_framework/test/data/instances/MOKP_250_2.dat"
>>> kp = KnapsackProblem(number_of_objective=2, instance_file=instance_file)
>>>
>>> # Generate a new solution
>>> solution = kp.generate_random_solution()
>>>
>>> # Print all decision variables of the solution
>>> print(solution.decision_vector)
>>>
>>> # Print all objectives values of the solution
>>> print(solution.F)
__init__(number_of_objective, instance_file=None, weights=None, profits=None, capacities=None)[source]

Constructor of the problem. You can initialize the problem directly by using an instance file or by setting parameters : weights, profits and capacities.

Parameters
  • number_of_objective – {int}

  • instance_file – {str} txt file of the instance: http://www-desir.lip6.fr/~lustt/Research.html#MOKP

  • weights – {list} weights of all objects available in knapsacks

  • profits – {list} profits of all objects available in knapsacks

  • capacities – {list} capacities of each knapsack

Methods

__init__(number_of_objective[, …])

Constructor of the problem.

evaluate(x)

Evaluate the given solution for the current problem and store the outcome

f(function_id, decision_vector)

Evaluate the decision_vector for the objective function_id

generate_random_solution()

Generate a random solution for the current problem

init_with_data(weights, profits, capacities)

init_with_instance_file(instance_file)

penality(function_id)

Compute the penality for the specific objective

profit_of_solution(function_id, solution)

Return the profit of the solution for the objective function_id

weight_of_solution(function_id, solution)

Return the weight of the solution for the objective function_id

dtype

alias of builtins.float

evaluate(x: Union[moead_framework.solution.base.Solution, Sequence]) → moead_framework.solution.one_dimension_solution.OneDimensionSolution

Evaluate the given solution for the current problem and store the outcome

Parameters

x – A {Solution} containing all decision variables

Returns

OneDimensionSolution

f(function_id: int, decision_vector: numpy.ndarray)[source]

Evaluate the decision_vector for the objective function_id

Parameters
  • function_id – {integer} index of the objective

  • decision_vector – {OneDimensionSolution} solution to evaluate

Returns

{float} fitness value

generate_random_solution()[source]

Generate a random solution for the current problem

Returns

{OneDimensionSolution}

penality(function_id)[source]

Compute the penality for the specific objective

Parameters

function_id – {integer} index of the objective function

Returns

{float} penality value

profit_of_solution(function_id, solution)[source]

Return the profit of the solution for the objective function_id

Parameters
  • function_id – {integer} index of the objective function

  • solution – {list<integer>} representation of the solution

Returns

{float} profit of the solution

weight_of_solution(function_id, solution)[source]

Return the weight of the solution for the objective function_id

Parameters
  • function_id – {integer} index of the objective function

  • solution – {list<integer>} representation of the solution

Returns

{float} weight of the solution