c# - 'Google.OrTools.ConstraintSolver.operations_research_constraint_solverPINVOKE' 的类型初始化程序引发异常
问题描述
我有一个谷歌路由网络服务。它适用于本地运行的项目。但是当我将它上传到主机上时,我收到以下错误消息:
'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 bool HasErr, 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;
}
为什么我会收到此错误?
解决方案
推荐阅读
- react-native - 反应:无法在 componentWillMount 中设置状态
- java - 如何使 JButton 仅可点击一次而不增加后续点击次数?
- python - How to add a new column with values based on conditions of other existing columns?
- laravel - Laravel Cascade Insert throught HasMany relationship
- azure - Is it that I can't edit an AKS cluster on Azure?
- android - 如何将通知徽章添加到日历日
- ios - 如何在方法中使属性可用(非 Null)?
- google-maps - 在 SAP 上使用 Google Maps API 时遇到 SSL 问题
- unity3d - Unity collision while rescaling
- reactjs - Why are Arrow Functions in ReactJS considered as property?