【问题标题】:GUROBI : Switching between cloud/regular modeGUROBI : 在云/常规模式之间切换
【发布时间】:2015-11-30 08:10:08
【问题描述】:

我们将 Gurobi WCF 解决方案托管为 Windows 服务。

                    if (useCloud)
                    {
                        this.logInfo("Environment GRB_LICENSE_FILE: " + System.Environment.GetEnvironmentVariable("GRB_LICENSE_FILE"));
                        return new GurobiProblemBuilder(this, new testSolver.solver.gurobi.Net.EnvironmentNet(this.settings.cloudLic, this.settings.cloudPwd));
                    }
                    else
                    {
                        this.logInfo("Environment GRB_LICENSE_FILE: " + System.Environment.GetEnvironmentVariable("GRB_LICENSE_FILE"));
                        return new GurobiProblemBuilder(this, new testSolver.solver.gurobi.Net.EnvironmentNet(null));             
                    }

在 UI 中,我们提供了转到云端的选项,并由“useCloud”标志处理。但问题是我们每次都必须重新启动服务才能在云/非云选项之间切换。即使正确设置了环境变量,服务也无法透明地在云/非云之间切换。

添加于 2015 年 12 月 1 日

    public EnvironmentNet(string logFileOrNull)
    {
        environment = new GRBEnv(null);        
    }

    public EnvironmentNet(string computeServer, string password)
    {
        // http://www.gurobi.com/documentation/6.0/refman/cs_grbenv2.html
        int port = -1; // read from app.config            
        int priority =  0; // read from app.config
        double timeout = -1; // read from app.config

        environment = new GRBEnv(null, computeServer, port, password,    priority, timeout);                            
    }

实际上,我们的 GurobiProblemBuilder 调用 GRBEnv,然后调用 GRBEnv(null) 或 GRBEnv(null,computeServer,port,password,priority,timeout) 版本取决于用户选择使用云服务器还是本地服务器。但是我们仍然无法在计算服务器和本地服务器之间透明地切换。这归结为 Gurobi 从 GRB_LICENSE_FILE 环境变量中获取许可证文件。是否有计划提供一种不同的方式将 GRB_LICENSE_FILE 传递给 Gurobi 求解器?

我们的解决方法: 我们的方法是当它是云时使用 GRB_LICENSE_FILE = gurobi.lic.cloud。如果是非云 GRB_LICENSE_FILE = gurobi.lic。我们可能需要使用一个通用的 gurobi.lic 文件并用计算服务器或常规服务器覆盖。

【问题讨论】:

    标签: c# .net wcf windows-services gurobi


    【解决方案1】:

    System.Environment.GetEnvironmentVariable 将返回当前进程(例如您的服务进程)的环境变量的当前值。进程环境变量只在进程启动时从系统环境变量中继承一次。因此,需要重新启动是预期行为。

    一般来说,如果您想使用具有不同许可证文件的多个 Gurobi 实例,您需要启动单独的进程。在 .NET 情况下,环境变量 GRB_LICENSE_FILE 的更改仅在加载 .NET 程序集之前考虑,通常是在您第一次创建 GRBEnv 对象时。

    但是,在您的情况下,可能会有更简单的解决方案。您始终可以创建 Gurobi Compute Server 环境并使用您的云服务器(请参阅http://www.gurobi.com/documentation/6.5/refman/cs_grbenv2.html)。

    GRBEnv(string logFileName,
           string computeserver,
           int port,
           string password,
           int priority,
           double timeout)
    

    您不需要云许可文件来创建计算服务器环境,因此请始终使用您的本地许可文件。在本地环境中创建模型以在本地计算机上求解模型,并在计算服务器环境中创建模型,以防您想在云中求解模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-17
      • 1970-01-01
      相关资源
      最近更新 更多