问题描述
我有一个谷歌路由网络服务。它适用于本地运行的项目。 但是当我将它上传到主机上时,我收到此错误消息:
类型初始化器 'Google.OrTools.ConstraintSolver.operations_research_constraint_solverPINVOKE' 抛出异常。
备注
1-我使用 vs 2019
2- 我在 Plesk 主机面板中将 enable-32-bit-application 设置为 false
3- 我用 64 位构建我的项目
4- 我通过包管理器下载安装了 google.ortool
我的代码是:
static List<int> PrintSolution(in RoutingModel routing,in RoutingIndexManager manager,in Assignment solution,ref bool HasErr,ref string ErrMsg)
{
List<int> orderIndex = new List<int>();
try
{
long routedistance = 0;
var index = routing.Start(0);
while (routing.IsEnd(index) == false)
{
orderIndex.Add((int)index);
var prevIoUsIndex = index;
index = solution.Value(routing.Nextvar(index));
routedistance += routing.GetArcCostForVehicle(prevIoUsIndex,index,0);
}
}
catch (Exception e)
{
HasErr = true;
ErrMsg = "GetIndexOrderLocations " + e.Message;
orderIndex = null;
}
return orderIndex;
}
public static List<int> GetIndexOrderLocations(/String[] args/long[,] distanceMatrix,ref string ErrMsg)
{
RoutingModel routing = null;
RoutingIndexManager manager = null;
Assignment solution = null;
List<int> Result = new List<int>();
try
{
// Instantiate the data problem.
DataModel data = new DataModel();
// Create Routing Index Manager
manager = new RoutingIndexManager(/ data./ distanceMatrix.GetLength(0),data.VehicleNumber,data.Depot);
// Create Routing Model.
routing = new RoutingModel(manager);
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex,long toIndex) => {
// Convert from routing variable Index to distance matrix NodeIndex.
var fromNode = manager.IndexToNode(fromIndex);
var toNode = manager.IndexToNode(toIndex);
return/* data.*/distanceMatrix[fromNode,toNode];
});
// Define cost of each arc.
routing.SetArcCostEvaluatorOfAllVehicles(transitCallbackIndex);
// Setting first solution heuristic.
RoutingSearchParameters searchParameters =
operations_research_constraint_solver.DefaultRoutingSearchParameters();
searchParameters.FirstSolutionStrategy = FirstSolutionStrategy.Types.Value.PathCheapestArc;
// Solve the problem.
solution = routing.solveWithParameters(searchParameters);
if (routing == null || manager == null || solution == null)
return null;
Result = PrintSolution(routing,manager,solution,ref HasErr,ref ErrMsg);
}
catch (Exception e)
{
HasErr = true;
ErrMsg = "GetIndexOrderLocations " + e.Message;
}
// Print solution on console.
return Result;
}
为什么会出现这个错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)