微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

“Google.OrTools.ConstraintSolver.operations_research_constraint_solverPINVOKE”的类型初始值设定项引发异常

如何解决“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 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 举报,一经查实,本站将立刻删除。