-2

Using Microsoft Solver Foundation, I have only solved linear problem so far. I'm now trying to solve a very simple non-linear problem but for some reasons, Microsoft solver cannot solve it.

The problem is maximising a0*a1 , with a0<10 and a1<20 . Here is the code I'm using:

using System;
using Microsoft.SolverFoundation.Services;

namespace SolverFoundationDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\nBegin Solver demo\n");

            var solver = SolverContext.GetContext();
            var model = solver.CreateModel();

            var decision1 = new Decision(Domain.RealNonnegative, "a0"); model.AddDecision(decision1);
            var decision2 = new Decision(Domain.RealNonnegative, "a1"); model.AddDecision(decision2);


            model.AddConstraint("Constraint0", "a0 <=10");
            model.AddConstraint("Constraint1", "a1 <=20");


             model.AddGoal("Goal", GoalKind.Maximize, " a0*a1 ");


            var solution = solver.Solve();

  
            Console.WriteLine("\nEnd Solver demo\n");
            Console.ReadLine();
        } 
    } 
} 

The error I get is " The model is not convex" , which is true but I was expecting Microsoft solver to be smart enough to find a solution anyway.

Thanks a lot for your feedback.

Regards,

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
jbf
  • 1
  • 2
  • What is the "smart" solution that you expect it to get? There is no maximum for the goal since you can make a0 and a1 negative and increase their magntitude as much as you want. I've never used microsfot solver but given there is no maximum for your goal I am not that surprised that it errors out at you... – Chris May 09 '18 at 11:35
  • Hi, you can see that a0 and a1 are RealNonnegative. So I would expect a0 to be 10 and a1 to be 20. Then the objective function would be 200. – jbf May 09 '18 at 12:14
  • Ah, sorry I missed that was in the code - I just read your description which didn't mention it. – Chris May 10 '18 at 08:14
  • It selects a (convex) QP solver. You should make it select the NLP solver (Knitro). BTW solver foundation has been discontinued years ago. – Erwin Kalvelagen May 10 '18 at 10:15

1 Answers1

-1

Actually, Microsoft Solver choose NLP by default. For some reasons, if I add a useless constraint like a0*a1 < 1000000, it works. If I don't add this constraint, it does not work.. I'm really not satisfied with this Solver. Erwin, could you please tell me which solver should I use If I want to switch from Microsoft solver?

My program is written is C#. I have all my decisions and constraints inside Datable, and I pass it to the solver like shown below. In order to avoid to re-write the whole stuff, I would like a solver that I can feed using the same method..

string Comment = Convert.ToString(Table_Constraints.Rows[i]["Comment"]);

string Constraints = Convert.ToString(Table_Constraints.Rows[i]["Constraint"]);

model.AddConstraint(Comment, Constraints);

jbf
  • 1
  • 2
  • This isn't an answer; please only post things as answers that *answer the question*. If you want to make a clarification to your question, please edit the question. – Eric Lippert May 11 '18 at 18:45
  • Note that *questions which ask for a recommendation for a book or tool or tutorial* are off topic on this site. – Eric Lippert May 11 '18 at 18:45