Hi, I’m Nathan Brixius. I typically write about machine learning, data science, software engineering, and sports. You can follow me on Twitter here.

I am a Senior Director at eBay, where I am head of Retail Standards Science. I have previously held executive level positions at 84.51, Frontline Systems and Nielsen, applying data science to critical business problems. I started my career at Microsoft as an engineer and manager. In 2000 I received my PhD in computer science from the University of Iowa.

The opinions on this blog are my own and do not necessarily represent those of my employer. Links may contain affiliate tags.

### Like this:

Like Loading...

Hello,

you must have been asked dozen of times. Apologize in advance.

MSF fits my need but express has limitation.

I am looking for the enterprise version to buy for days…no way.

any help or replacement package ? (fixed integer/constraints issues/simplex).

Merci

Vincent, the enterprise version of MSF is no longer being sold according to Microsoft. My suggestion is to connect directly with a solver vendor.

– Nate

Hi Nathan,

I am searching for a way to use a constraint solver, preferably Solver Foundation, to aid in automated unit testing to achieve maximum branch coverage. It works beautifully when there are no assignment statements inside the code block. However, when there are multiple assignments such as if (x < y) { x += y; y = x – y; x -= y; } … rest of function, then I get caught up in how to tell the constraint solver that these variables are changed.

How do I tell the constraint solver that there are assignment statements to take into account?

The most promising thing I've seen is what you've written about CQN, but I still can't make the connection between that and my problem.

If you can point me to something you've written or offer some other suggestions, I would be greatly appreciative.

Thank you,

Scott McNeany

Hey Nathan, just an update on the previous post. I figured out how to do assignment operators by just backtracking and replacing the variable with its history. So in my previous example y is actually becomes (x + y – y).

I do still have a question for you though. I can’t seem to find a modulo operator anywhere. There’s not a built in one that allows me to say model.AddConstraint(“c1”, x % y != 0); But supposedly, based on the documentation at http://msdn.microsoft.com/en-us/library/ff818505(v=vs.93).aspx, there should be a mod operator on the Model class. However, specifying model.AddConstraint(“c1”, Model.Mod(x, y) != 0) doesn’t work either. It says the Model class doesn’t contain a definition for “Mod”.

Any idea how to use the modulo operator?

Thanks,

Scott

Hi Scott, sorry for not replying to your previous comment. I confirmed that there is no Mod operator in the 3.1 version of Solver Foundation. You could define your own in terms of (integer) division and subtraction of Term objects, however.

No problem, thanks for getting back with me. That makes sense, but how exactly is that done?

I posted the same question on StackOverflow and someone recommended using Model.Floor(Model.Quotient(x,y))==Model.Ceiling(Model.Quotient(x,y)). This works for the Solve() method but DOES NOT work when doing context.FindAllowedValues(bindings) to get all combinations of valid values.

Any help you can provided would be much appreciated. Thank you.

Hi

Sorry for this elementary question but I´m a starter with microsoft solver fundation.

I´m programming with visual studio in C#.

I´m a starter (absolute virgin) with MSF and I need help to understand the modeling.

I have following problem to resolve:

Scheduling of production.

Workers:

Specialized pcs 10

General pcs 30

Machinery:

Machine1 pcs 10

Machine2 pcs 20

Machine3 pcs 05

Items to produce:

Item 1 pcs 1000

Item 2 pcs 5000

Bill of work:

Item 1:

Work1: Machine1 + Specialized Worker pcs/day 500

Work2: General worker pcs/day 1000

Work3: Machine2 StartUp with Specialized Worker one hour -> 1000 pcs/day -> End Work Specialized worker one hour

(Work1 priority 1, work2 and work3 have not priority)

Item 2:

Work1: General worker pcs/day 1000

Work2: Machine3 + General worker pcs/day 500

(work1 have priority on work2)

Time of Work: 8 hours/day five day/week no saturday/sunday

Start of work: 01/03/2013

Delivery Date: max 01/05/2013

I need to undestand how I can model this schedule with MSF.

Can you explain to me or suggest where I can found a similar sample to study ?

Thanking in advance for helping

Piercarlo

Good day Mr. Brixius,

I realize you are no longer with Microsoft, but as I was unable to locate the answer elsewhere, and since you are an expert in the field, I thought I would try my luck and ask for your assistance.

I am using the Quadratic Portfolio example that comes with Microsoft Solver Foundation 3.1. With the example, there are 5 stocks, but I would like to add a constraint that no more than 4 stocks can be included in the portfolio (in the solution). Is it possible to do that? If so, could you indicate how?

Thank you very much and I hope that you are enjoying your new work with Nielsen Marketing Analytics.

Regards,

David

This is the Solving part of the example where I should probably add the constraint.

public bool BuildRiskModel(DataTable plan, int iterations)

{

int m = StockNames.Length;

for (int reqIx = 0; reqIx < iterations; reqIx++)

{

InteriorPointSolver solver = new InteriorPointSolver();

int[] allocations = new int[m];

for (int invest = 0; invest < m; invest++)

{

string name = StockNames[invest];

solver.AddVariable(name, out allocations[invest]);

solver.SetBounds(allocations[invest], -1, 1);

}

int expectedReturn;

solver.AddRow("expectedReturn", out expectedReturn);

// expected return must beat the minimum asked

solver.SetBounds(expectedReturn, (double) plan.Rows[reqIx]["minimum"], double.PositiveInfinity);

int unity;

solver.AddRow("Investments sum to one", out unity);

solver.SetBounds(unity, 1, 1);

// expected return is a weighted linear combination of investments.

// unity is a simple sum of the investments

for (int invest = m; 0 <= –invest; )

{

solver.SetCoefficient(expectedReturn, allocations[invest], _means[invest]);

solver.SetCoefficient(unity, allocations[invest], 1);

}

// The variance of the result is a quadratic combination of the covariants and allocations.

int variance;

solver.AddRow("variance", out variance);

for (int invest = m; 0 <= –invest; )

{

for (int jnvest = m; 0 <= –jnvest; )

{

solver.SetCoefficient(variance, _covariance[invest, jnvest], allocations[invest], allocations[jnvest]);

}

}

// the goal is to minimize the variance, given the linear lower bound on asked return.

solver.AddGoal(variance, 0, true);

InteriorPointSolverParams lpParams = new InteriorPointSolverParams();

solver.Solve(lpParams);

if (solver.Result != LinearResult.Optimal)

return false;

for (int invest = m; 0 <= –invest; )

{

plan.Rows[reqIx][StockNames[invest]] = (double) solver.GetValue(allocations[invest]);

}

plan.Rows[reqIx]["actual"] = (double) solver.GetValue(expectedReturn);

plan.Rows[reqIx]["Std.Dev."] = Math.Sqrt((double)solver.Statistics.Primal);

}

return true;

}

David – did you ever find solution to this?

Hi Moon, No I did not. Good luck.

Hi David and Moon, sorry for not replying to this. MSF is no longer supported by Microsoft, unfortunately. The short answer is that such a constraint would require integer variables, which would turn the problem into a mixed integer quadratic program. This is not supported by MSF – but it is supported by solvers such as Gurobi, who also offer .NET APIs.

Hi Piercarlo, thank you for your question but I do not answer MSF questions anymore (unless they are trivial) since Microsoft stopped supporting Solver Foundation roughly 18 months ago.

Hi Nathan, Sorry to bother you. I am using MSF to solve a quad opt problem. I notice support for MSF is minimal on the forum. Do you know of an alternative product for c#? I quite like the MSF Solver and have converted their Stock Trading example to my needs – however, I would like to constrain the number of cardinals and I am at a loss as how to do this. Is there an alternative product where support is more readily available?

Hi Moon, my suggestion is to use Gurobi at Gurobi.com, or Frontline’s Solver Platform at solver.com.

Hi Nathan,

Thanks so much for the posting on “Solving traveling salesman problems using Solver Foundation” I left a note on that Blog, but wanted to ask your thoughts on asymmetrical matrixes.

I am solving a manufacturing changeover problem–go through 43 products with the lowest cost changeovers. But the problem is asymmetrical. Meaning Product1–>Product2 might cost more than going from Product2–>Product1.

I am having trouble making that work with your solution. Do you have any suggestions?

Steve

Hello,

I’m hoping my question is trivial, solver foundation is giving me incorrect values for Goal Coefficients lower and upper bound values is it a bug that never got fixed? All other values are spot on except for the Goal Coefficient upper and lower bounds. Hope you can answer my question.

a little code:

var solver = SolverContext.GetContext();

var model = solver.CreateModel();

………

Solution solution = solver.Solve(new SimplexDirective { GetSensitivity = true, GetInfeasibility = true });

LinearReport report = ((LinearReport)solution.GetReport());

Console.WriteLine(report);

Thanks

Adam Vega

Hi Nathan, Thx for your last reply (06 November 2014 at 2:55 am).

Hi Nathan,

one question, are you the one who published the paper “Solving semidefinite programs in Mathematica”. I got interested in it and wanted to download the Mathematica package you offered at the end of the paper but the website does not exist any longer. Is there any possibility that you could make this package reachable again?

Thank you, greets

Mauricio

Hi Mauricio,

Thanks for your interest in the package. In the 17+ years since I published the paper, I lost the software as it was stored on university servers. There are other, much better, ways to solve SDPs these days.

Regards, Nate

Hi Nate,

Thanks for your excellent posts.

How do I tackle a situation in which I have a dict(String, List) and the solver is required to vary all those values for each key!

I am confused on setting the decisions for such a case.

Is there any example I can refer to? I am totally lost here.

Any help is highly appreciated!

PD

Hi Nate – I was wondering if you can reccomend an independent contractor in Openrules – we have had some dialogue with the company directky but would like to speak with independent experience – any suggestions ? Thanks Peter