Optano.Modeling 不使用 MipCL
Optano.Modeling not working with MipCL
我刚开始测试 optano.modeling 库,我用这些包创建了一个新的控制台应用程序:
- Optano.Modeling
- Optano.Modeling.Gurobi
我复制了 Optano 页面 (http://docs.optano.net/modeling/current/userDoc/getting_started/step_install_primer.html) 中显示的默认程序,一切正常。
这是程序。
using System.Diagnostics;
using OPTANO.Modeling.Optimization;
using OPTANO.Modeling.Optimization.Enums;
using OPTANO.Modeling.Optimization.Solver.Gurobi80;
namespace optanodemo
{
class Program
{
static void Main(string[] args)
{
using (var scope = new ModelScope())
{
var model = new Model();
var x = new Variable("x");
var y = new Variable("y");
model.AddConstraint(x + y >= 120);
model.AddObjective(new Objective(2*x + 3*y));
using (var solver = new GurobiSolver())
{
var solution = solver.Solve(model);
}
}
}
}
}
之后我决定将求解器(因为我现在不想支付 Gurobi)更改为 MipCL 1.41,留下如下代码:
using System.Diagnostics;
using OPTANO.Modeling.Optimization;
using OPTANO.Modeling.Optimization.Enums;
using OPTANO.Modeling.Optimization.Solver.MipCL141;
namespace optanodemo
{
class Program
{
static void Main(string[] args)
{
using (var scope = new ModelScope())
{
var model = new Model();
var x = new Variable("x");
var y = new Variable("y");
model.AddConstraint(x + y >= 120);
model.AddObjective(new Objective(2*x + 3*y));
using (var solver = new MipCLSolver())
{
var solution = solver.Solve(model);
}
}
}
}
}
代码可以编译,但是当我 运行 它时,我收到异常:
Unhandled Exception: System.TypeInitializationException: The type initializer for
'OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'MipCL141WrapperCpp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_MipCL141WrapperCpp(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.SWIGExceptionHelper..ctor()
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE..cctor()
--- End of inner exception stack trace ---
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.new_CMIP__SWIG_0()
at OPTANO.Modeling.Optimization.Solver.MipCL141.MipCLSolver.BuildSolverModelAdapterSpecific(Int32 prioLevel)
at OPTANO.Modeling.Optimization.SolverBase.BuildConfigureAndSolveOnAdapter(Int32 prioLevel, Dictionary`2 variableValues, Boolean isResolve)
at OPTANO.Modeling.Optimization.SolverBase.SolveNonNative(Dictionary`2 variableValues, Boolean isResolve)
at OPTANO.Modeling.Optimization.SolverBase.Solve(Model model, Dictionary`2 variableValues)
at optanodemo.Program.Main(String[] args) in C:\Temp\test\ConsoleApp1\ConsoleApp1\Program.cs:line 21
经过 5 个小时的尝试,我决定在这里写信,看看是否有人遇到过类似的问题。
这是我试过的:
- 我检查了我的应用程序文件夹,文件 MipCL141WrapperCpp.dll 在文件夹中
- 我从 http://www.mipcl-cpp.appspot.com/download.html 下载了 MipCL 库版本 1.41,并安装了几次。
- 我将所有 MipCL 安装文件复制到我的应用程序文件夹
- 我将我的应用程序构建设置为 x64 而不是 Any
- 我反汇编了 MipCL141WrapperCpp.dll 以检查任何其他可能的依赖关系,我看到代码引用了 mipcl.dll、VCRUNTIME140D.dll 和 ucrtbased.dll。我还将这些文件复制到我的应用程序文件夹中。
你认为我还有什么可以尝试的吗?
Visual Studio 2017 没有在 windows\system32 文件夹中安装文件 ucrtbased.dll。它只安装文件 ucrtbase.dll.
我从互联网上下载了这个文件并将其添加到应用程序文件夹中,一切开始顺利进行。
我刚开始测试 optano.modeling 库,我用这些包创建了一个新的控制台应用程序:
- Optano.Modeling
- Optano.Modeling.Gurobi
我复制了 Optano 页面 (http://docs.optano.net/modeling/current/userDoc/getting_started/step_install_primer.html) 中显示的默认程序,一切正常。
这是程序。
using System.Diagnostics;
using OPTANO.Modeling.Optimization;
using OPTANO.Modeling.Optimization.Enums;
using OPTANO.Modeling.Optimization.Solver.Gurobi80;
namespace optanodemo
{
class Program
{
static void Main(string[] args)
{
using (var scope = new ModelScope())
{
var model = new Model();
var x = new Variable("x");
var y = new Variable("y");
model.AddConstraint(x + y >= 120);
model.AddObjective(new Objective(2*x + 3*y));
using (var solver = new GurobiSolver())
{
var solution = solver.Solve(model);
}
}
}
}
}
之后我决定将求解器(因为我现在不想支付 Gurobi)更改为 MipCL 1.41,留下如下代码:
using System.Diagnostics;
using OPTANO.Modeling.Optimization;
using OPTANO.Modeling.Optimization.Enums;
using OPTANO.Modeling.Optimization.Solver.MipCL141;
namespace optanodemo
{
class Program
{
static void Main(string[] args)
{
using (var scope = new ModelScope())
{
var model = new Model();
var x = new Variable("x");
var y = new Variable("y");
model.AddConstraint(x + y >= 120);
model.AddObjective(new Objective(2*x + 3*y));
using (var solver = new MipCLSolver())
{
var solution = solver.Solve(model);
}
}
}
}
}
代码可以编译,但是当我 运行 它时,我收到异常:
Unhandled Exception: System.TypeInitializationException: The type initializer for
'OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'MipCL141WrapperCpp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_MipCL141WrapperCpp(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.SWIGExceptionHelper..ctor()
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE..cctor()
--- End of inner exception stack trace ---
at OPTANO.Modeling.Optimization.Solver.MipCL141.WrapperCsharp.MipCL141WrapperCppPINVOKE.new_CMIP__SWIG_0()
at OPTANO.Modeling.Optimization.Solver.MipCL141.MipCLSolver.BuildSolverModelAdapterSpecific(Int32 prioLevel)
at OPTANO.Modeling.Optimization.SolverBase.BuildConfigureAndSolveOnAdapter(Int32 prioLevel, Dictionary`2 variableValues, Boolean isResolve)
at OPTANO.Modeling.Optimization.SolverBase.SolveNonNative(Dictionary`2 variableValues, Boolean isResolve)
at OPTANO.Modeling.Optimization.SolverBase.Solve(Model model, Dictionary`2 variableValues)
at optanodemo.Program.Main(String[] args) in C:\Temp\test\ConsoleApp1\ConsoleApp1\Program.cs:line 21
经过 5 个小时的尝试,我决定在这里写信,看看是否有人遇到过类似的问题。 这是我试过的:
- 我检查了我的应用程序文件夹,文件 MipCL141WrapperCpp.dll 在文件夹中
- 我从 http://www.mipcl-cpp.appspot.com/download.html 下载了 MipCL 库版本 1.41,并安装了几次。
- 我将所有 MipCL 安装文件复制到我的应用程序文件夹
- 我将我的应用程序构建设置为 x64 而不是 Any
- 我反汇编了 MipCL141WrapperCpp.dll 以检查任何其他可能的依赖关系,我看到代码引用了 mipcl.dll、VCRUNTIME140D.dll 和 ucrtbased.dll。我还将这些文件复制到我的应用程序文件夹中。
你认为我还有什么可以尝试的吗?
Visual Studio 2017 没有在 windows\system32 文件夹中安装文件 ucrtbased.dll。它只安装文件 ucrtbase.dll.
我从互联网上下载了这个文件并将其添加到应用程序文件夹中,一切开始顺利进行。