I am having issues with updating the reduced costs for the objective function of my subproblem which looks like so
Pricing subproblem formulation
Each Greek letter (pi, rho, and mu) are duals of the master problem formulation.
When making the duals of the constraints, I am using the master problem model here:
However on code: I have two classes (namely MasterProblem and Subproblem) where I would create the model for both. Using the master problem's constraints I was able to create the duals for each of the constraints
public void SaveDualValues()
{
piForCustomers = new Dictionary<CustomerNode, Double>();
foreach (CustomerNode c in _columnGeneration.rCustomerNodes) piForCustomers.Add(c, model.GetDual(row_customers[c]));
foreach (Vehicle v in _columnGeneration.vVehicles) rhoForVehicles.Add(v, model.GetDual(row_vehicles[v]));
foreach (Vehicle v in _columnGeneration.vVehicles) muForVehicles.Add(v, model.GetDual(row_charge[v]));
}
But when I try to update the objective function of the subproblem class, using image 1, here:
public void UpdateReducedCost()
{
ILinearNumExpr num_expr = model.LinearNumExpr();
double sum = 0;
foreach (Vehicle v in _columnGeneration.vVehicles)
{
foreach (Path path in _columnGeneration.paths)
{
foreach (CustomerNode i in _columnGeneration.rCustomerNodes)
sum += MasterProblem.piForCustomers[i] * path.x(i);
double benefit = path.benefit;
if (path.vehicles.Contains(v))
{
num_expr.AddTerm(
benefit -
sum -
(path.chargeNeeded * MasterProblem.rhoForVehicles[v]) -
MasterProblem.muForVehicles[v]
,
path.s
);
}
}
}
//reduced_cost.ClearExpr();
reduced_cost = model.AddMaximize(num_expr);
}
I get thrown this error which is Cplex.MultipleUseException error:
I would need to use both models as the duals cannot be made without using the model from the master problem and the duals are used for the objective function of the subproblem. Please help