Decision Optimization

 View Only
  • 1.  Float variables problem

    Posted Thu May 12, 2011 05:17 PM

    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 INumVarhttp://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


  • 2.  Re: Float variables problem

    Posted Fri May 13, 2011 12:35 AM

    Originally posted by: SystemAdmin


    It looks like you are using CP optimizer and not the CPLEX solver. Is this correct? If so then you might find better help in the CP optimizer forums.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Float variables problem

    Posted Fri May 13, 2011 03:08 AM

    Originally posted by: GuangFeng


    CP Optimizer does not support float decision variables, only float expressions. So the symptom looks to be expected, although I am not sure whether the error message is meaningful to you. For further inquires, please post a question by following the URL in Daniel's post.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Float variables problem

    Posted Fri May 13, 2011 06:44 AM

    Originally posted by: SystemAdmin


    Diego,

    CP Optimizer can solve problems on integer decision variables only. Floatting points variables are admitted but they must behave as an expression. That is they must be fixed to a value once all the integer variables are fixed. They cannot be decision variables.

    Apparently, you want to solve optimization problems with floatting-point decision variables. In this case, the way to go is to use CPLEX.

    Regards,

    Philippe
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Float variables problem

    Posted Fri May 13, 2011 03:22 PM

    Originally posted by: DiegoEm


    Thanks you for your reply. Actually I'm trying to solve an integert problem but was trying to run the relaxation to see how long does it take.

    I moved to use Cplex and it solves both problems. It solves the integers problem much faster the CP. Can you please add some details on CP vs Cplex?

    Thanks again,
    Diego.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Float variables problem

    Posted Mon May 16, 2011 08:28 AM

    Originally posted by: SystemAdmin


    Hi Diego,

    If your model has linear constraints, then using CPLEX is the way to go because CP solvers cannot do interesting inferences on these models with little structural information. If you solve, say a scheduling problem, and its structure fits the the CP modelling capabilities (with resources constraints, makespan, non-overlap constraint,...), then CP solvers are able to exploit this information to solve the problem more efficiently.

    You can have a look at the CP optimizer dcumentation to see the the examples provided and the special modelling objects that can be exploited.

    Philippe
    #CPLEXOptimizers
    #DecisionOptimization