Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to accessing intermediate solutions without declaring vars in Java?

    Posted 12/28/12 02:22 AM

    Originally posted by: SystemAdmin


    I find the example in DOCS: here.
    Well,in my project, the vars declarations are in .mod file only and I import them using :
    IloOplRunConfiguration rc0 = oplF.createOplRunConfiguration(DATADIR
                    + "/mod_v1.mod", DATADIR + "/data_v1_2.dat");//The model definition,specify the data source for the model
    

    Now, i want to print each solutions,like:
    while(cp.next()){
    ...
                    IloOplElement K = oplModel.getElement("K");//取出解中的K值oplModel=rc0.getOplModel()
                    double KNum = K.asNum();//取出解中的K值
                    newK=Double.toString(KNum);//取出解中的K值
    ...
                    System.out.println(newK);
    }
    

    The problem is: value of "newK" is always same as the first solution that cp has found.

    Does anyone familiar with this problem?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to accessing intermediate solutions without declaring vars in Java?

    Posted 12/30/12 10:52 PM

    Originally posted by: SystemAdmin


    I found a solution:
    
    IloOplFactory oplF = 
    
    new IloOplFactory();
    //The model definition IloOplRunConfiguration rc0 = oplF.createOplRunConfiguration(DATADIR + 
    "/mod_v1.mod", DATADIR + 
    "/data_v1_2.dat");
    //The model definition,specify the data source for the model IloOplModel oplModel=rc0.getOplModel();
    //The model itself oplModel.generate();
    //The model itself IloIntVar K = oplModel.getElement(
    "K").asIntVar();
    //取出解中的K值 IloIntVarMap CenInfs =oplModel.getElement(
    "CenInfs").asIntVarMap();
    //取出解中的CenInfs值 IloIntVarMap Compositions = oplModel.getElement(
    "Compositions").asIntVarMap();
    //取出解中的Compositions值  IloCP cp=rc0.getCP();
    //The solver cp.startNewSearch();
    //Start solving 
    
    int solCount=0;
    //计数:解的数量 
    
    while(cp.next())
    {
    //找到一个解,进行输出 solCount++;
    //解的数量加一 String newObj=Double.toString(cp.getObjValue());
    //解对应的目标函数值 String newK=
    "";
    //对应决策变量K:TAZ个数(见.mod文件) List<String> newCenInfs=
    
    new ArrayList<String>();
    //对应决策变量CenInfs:TAZ中心影响区(INF)的ID(见.mod文件) Map<String,List<String>> newCompositions=
    
    new HashMap<String,List<String>>();
    //对应决策变量Compositions:TAZ组成矩阵(见.mod文件) 
    
    double KNum =cp.getValue(K);
    //取出解中的K值 newK=Double.toString(KNum);
    //取出解中的K值 
    
    for(
    
    int i=1;i<=CenInfs.getSize();i++)
    {
    //取出解中的CenInfs值 
    
    if(cp.getValue(CenInfs.get(i))==1)
    { newCenInfs.add(Integer.toString(i));
    //取出解中的CenInfs值,保存被选中为中心INF的INF的Id,例如:[2,3,4,11] 
    } 
    } 
    //取出解中的Compositions值 
    
    for(
    
    int i=0;i<newCenInfs.size();i++)
    {;
    //取出解中的Compositions值:取出第i个中心INF的TAZ的Compositions String thisCenInfIdStr=newCenInfs.get(i);
    //例如:i=0,thisCenInfIdStr="2" 
    
    int thisCenInfId=Integer.parseInt(thisCenInfIdStr);
    //int型的thisCenInfIdStr List<String> CellIdsOfNewComps=
    
    new ArrayList<String>(); 
    
    for(
    
    int j=1;j<=Compositions.getSub(thisCenInfId).getSize();j++)
    { 
    
    if(cp.getValue(Compositions.getSub(thisCenInfId).get(j))==1)
    { String thisCellIdStr=Integer.toString(j); CellIdsOfNewComps.add(thisCellIdStr); 
    } 
    } newCompositions.put(thisCenInfIdStr,CellIdsOfNewComps); 
    } Solution oneSol=
    
    new Solution(newObj,newK,newCenInfs,newCompositions);
    //根据该解的结果创建一个solution printSolution(oneSol); writeSolution_TXT(oneSol,fatFolder,Integer.toString(solCount)); fea_Sols.add(oneSol); 
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to accessing intermediate solutions without declaring vars in Java?

    Posted 01/02/13 02:25 AM

    Originally posted by: SystemAdmin


    Since your code uses OPL you are probably better off asking this question on the OPL forum. There you will find the experts to answer your question and/or discuss the solution you found.
    #CPLEXOptimizers
    #DecisionOptimization