Originally posted by: DiegoEm
Hi, I have a C# code solving a problem with int variables. I tried to change the variables type to float and the code stopped working. this is my code:
CP cp = new CP();
INumVar[] assignment = null;
INumExpr profit = null;
assignment = new INumVar
http://parameters.NumberOfItems;
INumExpr total = cp.NumExpr();
for (int i = 0; i < parameters.NumberOfItems; i++)
{
assignment[i] = cp.NumVar(0, parameters.UnitsAvaialble[i], NumVarType.Float);
total = cp.Sum(total, assignment[i]);
}
cp.Add(cp.Le(total, 15));
profit = cp.NumExpr();
//Adding revenue for each delivered item
for (int i = 0; i < parameters.NumberOfItems; i++)
profit = cp.Sum(profit, cp.Prod((parameters.RevenueForItem[i]), assignment[i]));
cp.Add(cp.Maximize(profit));
cp.SetParameter(CP.IntParam.LogVerbosity, CP.ParameterValues.Verbose);
cp.Solve();
Console.WriteLine("profit: " + cp.GetValue(profit));
for (int i = 0; i < parameters.NumberOfItems; i++)
{
Console.Write(" Item " + (int)(i + 1) + ": " + cp.GetValue(assignment[i]));
}
Console.ReadLine();
This code fails throwing a "variable is not fixed" exception while trying to get the profit value. In the console I noticed the number of variables is 0.
Changing NumVarType.Float to NumVarType.Int fixes it. But I'd like my variables to be float.
What am I missing here???
Thanks,
Diego.
#CPLEXOptimizers#DecisionOptimization