Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k 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 Reply

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 
*/ 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...