2015-11-30 21 views
1

我們將Gurobi WCF解決方案作爲Windows服務託管。GUROBI:在雲端/普通模式之間切換

    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));    
        } 

在用戶界面中,我們提供了轉到雲端並由'useCloud'標誌處理的選項。但問題是我們必須每次重新啓動服務以在雲/非雲選項之間切換。即使在正確設置環境變量之後,服務也無法透明地在雲/非雲之間切換。

添加於01日 - 12月2015年

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(空)或GRBEnv(NULL,computeServer,端口,密碼,優先級,超時)版本取決於用戶選擇使用雲或本地服務器。但是我們仍然無法在計算服務器和本地服務器之間透明地切換。這歸結爲Gurobi從GRB_LICENSE_FILE環境變量中獲取許可證文件。有沒有計劃提供一種將GRB_LICENSE_FILE傳遞給Gurobi解算器的不同方式?

我們的解決方法: 我們的方法是在使用雲時使用GRB_LICENSE_FILE = gurobi.lic.cloud。如果它是非雲GRB_LICENSE_FILE = gurobi.lic。我們可能需要使用一個通用的gurobi.lic文件並用計算服務器或常規服務器覆蓋。

回答

1

System.Environment.GetEnvironmentVariable將返回當前進程(例如您的服務進程)的環境變量的當前值。當進程啓動時,進程環境變量只能從系統環境變量繼承。因此需要重啓是預期的行爲。

一般來說,如果您想要使用具有不同許可證文件的多個Gurobi實例,則需要啓動單獨的進程。在.NET中,只有在加載.NET程序集之前才考慮更改環境變量GRB_LICENSE_FILE,通常是在首次創建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) 

你並不需要一個雲許可文件創建計算服務器的環境中,所以乾脆一直使用本地許可文件。在本地環境中創建模型以在本地計算機上解決您的模型,並在您希望在雲中解決您的模型的情況下在Compute Server環境中創建模型。

相關問題