locked
Where is the error in my code when describing the model? RRS feed

  • Question

  • Dear all,

    Here is the optimization model I want to solve:

    while I have written the following code to describe it:

                SolverContext context = SolverContext.GetContext();
                Model model = context.CreateModel();

                Parameter v = new Parameter(Domain.RealNonnegative, "v");
                double voltage = 1.0;
                v.SetBinding(voltage);
                Parameter theta = new Parameter(Domain.RealRange(-Math.PI, Math.PI), "theta");
                double phaseangle = 0.0;
                theta.SetBinding(phaseangle);
                model.AddParameters(v, theta);

                Decision n = new Decision(Domain.Real, "n");
                model.AddDecision(n);

                Goal goal = model.AddGoal("voltage_offset", GoalKind.Minimize, Model.Abs(v - 1.0));

                model.AddConstraint("p_balance", v * Model.Cos(theta) - v * v == 0.1);
                model.AddConstraint("q_balance", v * Model.Sin(theta) == 0.1 * (0.8 - n));

                Solution solution = context.Solve();
                Console.Write("{0}", report);
                Console.WriteLine("The value of {0} is: {1}", goal.Name, goal.ToString());

    When I run the above code, the console will display:

    ===Solver Foundation Service Report===
    Date: 2012/7/31 16:56:53
    Version: Microsoft Solver Foundation 3.0.2.10889 Express Edition
    Model Name: DefaultModel
    Capabilities Applied: LP
    Solve Time (ms): 25
    Total Time (ms): 84
    Solve Completion Status: Infeasible
    Solver Selected: Microsoft.SolverFoundation.Solvers.SimplexSolver
    Directives:
    Microsoft.SolverFoundation.Services.Directive
    Algorithm: Primal
    Arithmetic: Exact
    Variables: 2 -> 1 + 0
    Rows: 3 -> 0
    Nonzeros: 2
    Eliminated Slack Variables: 0
    Basis: Slack
    Pivot Count: 0
    Phase 1 Pivots: 0 + 0
    Phase 2 Pivots: 0 + 0
    Factorings: 0 + 0
    Degenerate Pivots: 0 (0.00 %)
    Branches: 0
    The value of voltage_offset is: Infinity

    It seems that the model have invoked the simplex solver, however, it is absolutely wrong, since the value of the object function is infinity. Can anybody help me to find the error? Many thanks in advance!

    Regards

    Tuesday, July 31, 2012 8:58 AM

Answers

  • Your model is not well defined. As v and theta are parameters, there is no objective left and also the first constraint does not contain any variable. The model is recognized as an LP as the only thing left is the second constraint which is linear in n.

    I suspect you are confused about the role of parameters and variables (decisions). If you don't understand those concepts it will be very difficult to implement any model in a correct fashion.

    ----------------------------------------------------------------
    Erwin Kalvelagen
    Amsterdam Optimization Modeling Group
    erwin@amsterdamoptimization.com
    http://amsterdamoptimization.com
    ----------------------------------------------------------------
    
    • Marked as answer by Zhigang Wu Thursday, August 2, 2012 6:23 AM
    Tuesday, July 31, 2012 2:59 PM

All replies

  • Your model is not well defined. As v and theta are parameters, there is no objective left and also the first constraint does not contain any variable. The model is recognized as an LP as the only thing left is the second constraint which is linear in n.

    I suspect you are confused about the role of parameters and variables (decisions). If you don't understand those concepts it will be very difficult to implement any model in a correct fashion.

    ----------------------------------------------------------------
    Erwin Kalvelagen
    Amsterdam Optimization Modeling Group
    erwin@amsterdamoptimization.com
    http://amsterdamoptimization.com
    ----------------------------------------------------------------
    
    • Marked as answer by Zhigang Wu Thursday, August 2, 2012 6:23 AM
    Tuesday, July 31, 2012 2:59 PM
  • Dear Erwin,

    Thank you very much, I got the result after I defined v and theta as decisions.

    Regards

    Zhigang Wu

    Thursday, August 2, 2012 6:24 AM