.. _sec-KnapsackModels: Knapsack Models =============== LOGOS contains a set of knapsack models that can be used in combination with RAVEN when the desired optimization problem requires specific models to generate the knapsack parameters. More specifically, all these models can be included in a RAVEN :xmlNode:`EnsembleModel`, and RAVEN optimization methods (e.g., genetic algorithms) can then be employed to find the optimal solution. .. _subsec-SimpleKnapsackModel: Simple Knapsack Model --------------------- This model corresponds to the classical knapsack problem, characterized by a set of elements that can be chosen (or not). The goal is to maximize the sum of the chosen element values, subject to the constraint that the sum of their cost values does not exceed a capacity constraint (specified via a variable defined in the node). The IDs of the variables representing cost, value, and choice of each element are indicated in the node. The model generates two variables: - the validity of the chosen solution (specified in the node): either valid (0) or invalid (1) if the capacity constraint is not satisfied; - ``totalValue`` (specified in the node): the sum of the values of the chosen elements. When calculating the objective variable, if the constraint is not satisfied, then the variable is penalized by multiplying the project value by :math:`-1`. Example LOGOS input XML for ``SimpleKnapsackModel``: .. code-block:: xml element1Status,element2Status,element3Status, element4Status,element5Status,element1Val, element2Val,element3Val,element4Val, element5Val,element1Cost,element2Cost, element3Cost,element4Cost,element5Cost, validity,totalValue,capacityID capacityID 1. validity totalValue element1Status element2Status element3Status element4Status element5Status .. _subsec-MultipleKnapsackModel: MultipleKnapsack Model ---------------------- This model considers the multiple knapsack problem, characterized by a set of elements that can be chosen (or not) across multiple knapsacks. The goal is to maximize the sum of the chosen element values, subject to the capacity constraints of each knapsack. The capacity of each knapsack is defined in the node. As before, the IDs of the variables that represent cost, value, and choice of each element are indicated in the node. The model generates two variables: - the validity of the chosen solution (specified in the node): either valid (0) or invalid (1) if any capacity constraint is not satisfied; - ``totalValue`` (specified in the node): the sum of the values of the chosen elements. When calculating the objective variable, if any capacity constraint is not satisfied, then the variable is penalized by multiplying the project value by :math:`-1`. Example LOGOS input XML for ``MultipleKnapsackModel``: .. code-block:: xml e1Status,e2Status,e3Status,e4Status,e5Status, e1Val ,e2Val ,e3Val ,e4Val ,e5Val, e1Cost ,e2Cost ,e3Cost ,e4Cost ,e5Cost, validity,totalValue, K1_cap,K2_cap,K3_cap K1_cap K2_cap K3_cap 1. validity totalValue e1Status e2Status e3Status e4Status e5Status