我刚刚开始测试optano.modeling库,并使用这些包创建了一个新的控制台应用程序:
我复制了Optano (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个小时的努力,我决定写这里看看是否有类似的问题。这就是我试过的:
你觉得我还能尝试些什么吗?
发布于 2018-07-09 21:15:44
Visual 2017没有在windows\system32 32文件夹中安装文件ucrtbased.dll。它只安装文件ucrtbase.dll。
我从互联网上下载了这个文件,并将它添加到应用程序文件夹中,一切都开始顺利进行。
https://stackoverflow.com/questions/51253408
复制相似问题