首页 > 解决方案 > '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;
}

为什么我会收到此错误?

标签: c#google-mapsgoogle-apior-tools

解决方案


推荐阅读