google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11.26k stars 2.13k forks source link

Solver.Solve() returns an int, not Solver.ResultStatus (which doesn't exist) #1802

Closed MrYossu closed 4 years ago

MrYossu commented 4 years ago

I'm trying to follow the example at https://developers.google.com/optimization/mip/integer_opt using C# in LinqPad. I have copied out the code, but get a compiler error on the line...

Solver.ResultStatus resultStatus = solver.Solve();

...as the method Solve() returns an int, not a Solver.ResultStatus. Furthermore, I can't find a type Solver.ResultStatus anywhere.

I have a using for Google.OrTools.LinearSolver as directed.

Here is the complete LinqPad file (note that this is the contents of the file, not what you type in the editor, as it includes the query metadata)...

<Query Kind="Statements">
  <Output>DataGrids</Output>
  <Reference Relative="..\..\..\AppData\Local\LINQPad\NuGet.FW46\Google.OrTools\Google.Protobuf.3.10.0\lib\net45\Google.Protobuf.dll">&lt;LocalApplicationData&gt;\LINQPad\NuGet.FW46\Google.OrTools\Google.Protobuf.3.10.0\lib\net45\Google.Protobuf.dll</Reference>
  <NuGetReference>Google.OrTools.x86</NuGetReference>
  <Namespace>Google.OrTools.LinearSolver</Namespace>
</Query>

Solver solver = Solver.CreateSolver("SimpleMipProgram", "CBC_MIXED_INTEGER_PROGRAMMING");
Variable x = solver.MakeIntVar(0.0, double.PositiveInfinity, "x");
Variable y = solver.MakeIntVar(0.0, double.PositiveInfinity, "y");
solver.Add(x + 7 * y <= 17.5);
solver.Add(x <= 3.5);
solver.Maximize(x + 10 * y);
var resultStatus = solver.Solve();

The compiler error is on the last line.

Any ideas? Thanks

lperron commented 4 years ago

Which version of or-tools?

Le lun. 23 déc. 2019 à 22:26, Avrohom Yisroel Silver (Mr Yossu) < notifications@github.com> a écrit :

I'm trying to follow the example at https://developers.google.com/optimization/mip/integer_opt using C# in LinqPad. I have copied out the code, but get a compiler error on the line...

Solver.ResultStatus resultStatus = solver.Solve();

...as the method Solve() returns an int, not a Solver.ResultStatus. Furthermore, I can't find a type Solver.ResultStatus anywhere.

I have a using for Google.OrTools.LinearSolver as directed.

Any ideas? Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/1802?email_source=notifications&email_token=ACUPL3OVNSQYGZE4DFAAPP3Q2EUGVA5CNFSM4J6YGJX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICM3VQQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUPL3PJNVKZAV2LOW3AJT3Q2EUGVANCNFSM4J6YGJXQ .

lperron commented 4 years ago

Version too old.

MrYossu commented 4 years ago

So how do I use the latest? As I mentioned in my other issue, if I install the Google.OrTools v7.4.7247 Nuget package, then when I try to run any code, I get an exception...

Could not load file or assembly 'file:///C:\Users\myuser\AppData\Local\LINQPad\NuGet.FW46\Google.OrTools\Google.OrTools.7.4.7247\lib\net452\Google.OrTools.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

How do I use the latest from LinqPad?

MrYossu commented 4 years ago

OK, I see you've closed this, so I will open a new issue for my (now slightly different) question.