1

I have a model written in OPL, that is called from VBA. Afterwards an execute block is made, but when the call from VBA is made, the execute block does not run.

// Create Parameters:
 {string} G1 = ...; // Set of teams in first group
 {string} G2 = ...; // Set of teams in second group
 {string} G3 = ...; // Set of teams in third group
 {string} G4 = ...; // Set of teams in fourth group
 
 {string} Teams = G1 union G2 union G3 union G4;
 
 
 tuple Match {string team1; string team2;}
 
 {Match} Matches_G1 = {<t1,t2>| ordered t1,t2 in G1};
 {Match} Matches_G2 = {<t1,t2>| ordered t1,t2 in G2};
 {Match} Matches_G3 = {<t1,t2>| ordered t1,t2 in G3};
 {Match} Matches_G4 = {<t1,t2>| ordered t1,t2 in G4};
 {Match} MD2 = ...;
 {Match} MD6 = ...;
 {Match} MD10 = ...;
 {Match} MD4 = ...;
 {Match} MD8 = ...;
 {Match} MD12 = ...;
 {Match} M_G12 = Matches_G1 union Matches_G2; //All matches for the first two groups
 {Match} M_G34 = Matches_G3 union Matches_G4; //All matches for the second two groups
 
 {Match} M = M_G12 union M_G34;
 
 {Match} matchForTeam[t in Teams] = {m| m in M : m.team1 == t || m.team2 == t}; //List of all teams
 
 
 {string} S =...; //Set of stadiums
 
 {string} T = ...; //Set of kick off times
 
 {string} D = ...; //Set of kick off days
 
 int K[D][S][T] = ...; //Predetermined schedule between stadium and kickoff time
 
 float VT[M][T] = ...; //Value of match M is played at Time T according to TV distribution

 float VH[M][S] = ...; //Value of match M is played at stadium S according to Hospitality
 
 int V[M] = ...;
 
 int Treshold = ...;
 
 //float W = 4;
 //float Q = 1000;
 
 // Decision Variables:
 
 dvar int X[M][S][T] in 0..1; // if match M is played at stadium S at time T
 
 dvar int Dist; //Object function for distribution
 
 dvar int Hosp; //Object function for Hopsitality
 
 dvar int Village[M][S] in 0..1; //If village build at stadium S
 
  //////////// OBJECTIVE FUNCTION ///////////////
 
 maximize 
    1000*Dist+0.1*Hosp;
    
 //////////// CONSTRAINTS ///////////////
 
subject to{ 

Dist == sum(m in M, s in S, t in T) VT[m][t]*X[m][s][t];
Hosp == sum(m in M, s in S, t in T) VH[m][s]*X[m][s][t];

Block of code...


 }
 
 
execute {
    var cd = new IloOplOutputFile("resbi2.txt");
        for(var m in M)
            for(var s in S)
                for(var t in T)
                    cd.writeln(thisOplModel.X[m][s][t]);
                    
            cd.close();
            
    writeln("schedule: ", X);
}   

If I run it directly in CPLEX then it is not a problem, the file is created. But this is not happening when the call from VBA is made. Any ideas how to solve this? Thanks in advance.

shau
  • 11
  • 1

1 Answers1

1

can you change

var cd = new IloOplOutputFile("resbi2.txt");

into an absolute path like

var cd = new IloOplOutputFile("c:\\resbi2.txt");

?

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • "I tried this, this is not accepted." ==> What do you mean ? Do you get an error message ? If yes, what is the message ? – Alex Fleischer Jan 26 '22 at 10:57
  • I tried this, this is not accepted. The thing I found weird is it worked on my old computer. I have moved it all to a new and changed the path of course. The file is created if I solve the problem directly in CPLEX, but is not created when I run it from VBA. The VBA code is: `Public Sub OPL_Bicri_1() Dim AB As String AB = "C:\Program Files\IBM\ILOG\CPLEX_Studio_Community201\opl\bin\x64_win64\oplrun.exe C:\Users\shau\Documents\BiCriteria_1\BiCriteria_1.mod C:\Users\shau\Documents\BiCriteria_1\BiCriteria_1.dat" shell AB End Sub` – shau Jan 26 '22 at 12:07
  • Well, my bad, now it works when I run it directly in CPLEX. But it still does not work when I make the call from VBA. It seems like it quickly opens the commando prompt. It has to be mentioned that I just moved it all from my study computer to a work computer. It worked fine at the study computer. – shau Jan 27 '22 at 08:22
  • Ok so why not trying this ? Have your complete oplrun command in a callopl.bat and then from VBA you just call this .bat ? – Alex Fleischer Jan 27 '22 at 08:38
  • Okay, I just have to figure that out. But I just found out that if I want to run the model from command prompt it says that the problem size limit is exceeded, but we have bought the developer version and I have typed the API. But can there be an issue here? So the system thinks it is the community edition? – shau Jan 27 '22 at 09:18
  • You should change the path : C:\Program Files\IBM\ILOG\CPLEX_Studio_Community201 is the community edition – Alex Fleischer Jan 27 '22 at 10:04
  • ok, but this is where it is saved. should I uninstall and then download the other one. The mail I received just said it was enough to enter the API key. – shau Jan 27 '22 at 10:18
  • It is solved together with the team from IBM! – shau Jan 28 '22 at 10:21