0

I'm using Microsoft Solver Foundation Express eddition in my program, Express version is limited in model size according this link.

Is there any way to find how many:

  • Terms
  • Variables
  • Constraints
  • Non-Zeros

I defined in my model, using code?

Masoud
  • 8,020
  • 12
  • 62
  • 123

1 Answers1

1

The Model class maintains Decisions and Constraints as collections. You could enumerate those and count them.

To keep track of your Term variables, you could create and count them by your own constructor method.

Example:

static Term NewTerm(Term t)
{
    noOfTerms++;   //  defined as class variable somewhere else
    return t;
}

static void Main(string[] args)
{
    var context = SolverContext.GetContext();
    var model = context.CreateModel();
    double sqrt2 = Math.Sqrt(2.0);

    var t = new Decision(Domain.RealRange(-sqrt2, +sqrt2), "t");
    var u = new Decision(Domain.RealRange(-2 * sqrt2, +2 * sqrt2), "u");

    model.AddDecisions(t, u);

    Term P = NewTerm(2 * t * t / (3 * t * t + u * u + 2 * t) - (u * u + t * t) / 18);

    model.AddGoal("objective", GoalKind.Maximize, P);

    Console.WriteLine("Constraints: " + model.Constraints.Count());
    Console.WriteLine("Decisions:   " + model.Decisions.Count());
    Console.WriteLine("Goals:       " + model.Goals.Count());
    Console.WriteLine("Terms:       " + noOfTerms);

    Solution sol = context.Solve();
    Report report = sol.GetReport();
    Console.WriteLine(report);
    Console.WriteLine();
}

You are probably aware that Microsoft does no longer actively promote the Microsoft Solver Foundation.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54
  • Thanks, you said "To keep track of your Term ....", could you please explain more with piece of code, maybe? – Masoud Oct 25 '15 at 15:36
  • Yeah I know that Microsoft does no longer activity promote the MSF, whats your suggestion for its replacement? – Masoud Oct 26 '15 at 13:31
  • 1
    [Minizinc](http://www.minizinc.org/) and/or Gecode might be worth looking at. Also, SMT solvers like Z3 or Clasp could be useful. – Axel Kemper Oct 26 '15 at 13:55
  • 1
    Another candidate could be [Google OR Tools](https://developers.google.com/optimization/). – Axel Kemper Oct 26 '15 at 13:59
  • Can I check how many non-zeros my model has? Because in my case, it's giving me an error: Model size limit has been exceeded for this version of the product. Please contact Microsoft Corporation for licensing options. Limits: NonzeroLimit = 100000, MipVariableLimit = 2000, MipRowLimit = 2000, MipNonzeroLimit = 10000, CspTermLimit = 25000, Expiration = none. I need to check which limit has exceeded. @AxelKemper – Amit Madan Oct 01 '19 at 21:06
  • @AmitMadan: You probably have to count the variables while creating/adding them. My answer shows how to count `Term` objects. In a similar fashion, you could wrap the `Decision` creation and count in the wrapper function. – Axel Kemper Oct 02 '19 at 07:24