IBM ILOG Solver User's Manual > Local Search > Combining Complete and Local Search: Locating Warehouses > Model > Build constraints and variables |
Build constraints and variables |
INDEX
![]() |
We build the problem variables using the classes and expressions we have just defined. The numerical array offer
is used to store the number of the warehouse to which each client is assigned. The numerical array transCost
is used to store the cost of serving a client from the chosen warehouse. The 0-1 variable array open
is used to store the values that indicate whether a warehouse is built or not. The numerical array load
is used to store the sum of the demands of the clients served by each warehouse.
We add constraints to ensure that the load of customers assigned to a warehouse do not exceed the warehouse capacity.
IlcInt i; for (i = 0; i < nbWhouses; i++) load[i] = IloIntVar(env, 0, capacities[i]); m.add(IloPack(env, load, offer, demands)); |
We add a constraint that specifies that a warehouse is built (open
) if and only if it has assigned clients to serve.
// Only open if customers are served. for (i = 0; i < nbWhouses; i++) m.add(open[i] == (load[i] != 0)); m.add(IloScalProd(open, capacities) >= IloSum(demands)); |
We also add a variable, cost
, and set it as equal to the sum of the total client service costs for each warehouse (transCost
) plus the total building costs (buildCosts
) for all open warehouses.
// Total cost is sum of shipment and build costs IloIntVar cost(env, 0, IloIntMax); cost.setName("Cost\t"); m.add(cost == IloSum(transCost) + IloScalProd(open, buildCosts)); |
Finally, we add the element constraint that links the client service costs for a warehouse to the customers served by that warehouse.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |