Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

cplex - How to run multiple .dat files in the same model with using flow control?

I have a MIP model in CPLEX. I try to use a heuristic algorithm with using flow control. I need to use multiple ".dat" files and get the decision variables solution value in each time I solve the problem. I tried to used "addDataSource" but I have got no solution available error. When I try to solve without "addDataSource" I do not get this error. How can I handle with this problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

see several dat files in

https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/

{string} datFiles={"zoodat.dat","zoodat2.dat"};
    
    main
    {
      var source = new IloOplModelSource("zoodat.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
     
      for(datFile in thisOplModel.datFiles)
      {
         writeln("with ",datFile);
         var opl1 = new IloOplModel(def,cplex);
         var data1=new IloOplDataSource(datFile);
          opl1.addDataSource(data1);
        
          opl1.generate();
          cplex.solve();
          opl1.postProcess();
          writeln();
   

        }

 }
 
 /*
 
 which gives
 
 with zoodat.dat
The minimum cost is 380
We will use 6 40 seats buses and 2 30 seats buses 
with zoodat2.dat
The minimum cost is 500
We will use 10 40 seats buses and 0 30 seats buses 
*/ 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...