SUBHADARSHINI PANDA
SUBHADARSHINI PANDA

Reputation: 11

Inconsistent Runtime Performance in CPLEX OPL Optimization Problem Solving

I am solving am optimization problem in Cplex opl of version 12.10. The problem is formulated as a Mixed Integer Cone Programming model. I execute the code separately for each of the 24 hours of the day, altering the input data accordingly. The optimization process varies in time; for certain hours, the results are obtained within 3 to 4 minutes, while for others, it takes up to 25 minutes to achieve the optimal solution.

My optimization problem involves determining the optimal switch statuses for a power network with 37 switches. The primary objective is to minimize the losses of the network while maintaining the radial structure of the network while implementing necessary reconfigurations.The optimization problem determines the optimal status of the switches.5 switches should be open in each hour. The optimization process is conducted for each hour of the day, considering varying load conditions to find out five open switches. I observe significant variation in computation times, with some hours producing results within a few minutes, while others require 25 to 30 minutes

Upvotes: -1

Views: 43

Answers (1)

Alex Fleischer
Alex Fleischer

Reputation: 10059

I encourage you to have a look at "Evaluating variability" in the CPLEX documentation.

This will help you hedge against good and bad luck.

This is available in OPL and other APIs

Evaluating variability

CPLEX solves a problem multiple times to evaluate variability.

CPLEX can solve the same mixed integer problem multiple times, each time using a different random seed. Exercising this tool can serve as a surrogate for random perturbation of your model. In fact, exercising this tool can help you evaluate the variability of the class of problems that your instance belongs to. Tip: Your problem must be one of the following types of problem:

mixed integer linear program (MILP)
mixed integer quadratic program (MIQP)
mixed integer quadratically constrained program (MIQCP)

To invoke this procedure, follow these steps:

First, enter or read your model, so that your problem is currently in memory and available to CPLEX.
Optionally, set CPLEX parameters in the usual way; these settings will be applied on every run.
Then invoke the following command, where n specifies the number of times that you want CPLEX to solve your problem for comparison.

NB: You can also write some code like https://github.com/AlexFleischerParis/howtowithopl/blob/master/randomseedvariability.mod

    int n=30; // number of random seeds
    int d[1..n]; // duration
    int o[1..n]; // objective
    int iter[1..n]; // iterations
     
     // start of the model we want to test
     
     int Fixed        = 100;
    int NbWarehouses = 50;
    int NbStores     = 200;

    assert( NbStores > NbWarehouses );

    range Warehouses = 1..NbWarehouses;
    range Stores     = 1..NbStores;
    int Capacity[w in Warehouses] =
      NbStores div NbWarehouses +
      w % ( NbStores div NbWarehouses );
    int SupplyCost[s in Stores][w in Warehouses] =
      1 + ( ( s + 10 * w ) % 100 );
    dvar int Open[Warehouses] in 0..1;
    dvar float Supply[Stores][Warehouses] in 0..1;
    dexpr int TotalFixedCost = sum( w in Warehouses ) Fixed * Open[w];
    dexpr float TotalSupplyCost = sum( w in Warehouses, s in Stores )  SupplyCost[s][w] * Supply[s][w];
    minimize TotalFixedCost + TotalSupplyCost;

    subject to {
      forall( s in Stores )
        ctStoreHasOneWarehouse:
          sum( w in Warehouses )
            Supply[s][w] == 1;
      forall( w in Warehouses )
        ctOpen:
          sum( s in Stores )
            Supply[s][w] <= Open[w] * Capacity[w];
    }
     
    // end of the model we want to test


    main {

    thisOplModel.generate();


    var sum_d=0;
    var sum_o=0;;
    var sum_iter=0;

    writeln("seed objective iteration   runtime");

    for(var i=1;i<=thisOplModel.n;i++)
    {

        var opl=new IloOplModel(thisOplModel.modelDefinition);
        opl.generate();

        cplex.randomseed=i;

        
        
        
        var d1=new Date();
        cplex.solve();
        var d2=new Date();
        
        thisOplModel.d[i]=d2-d1;
        sum_d+=d2-d1;
        thisOplModel.d[i]=d2-d1;
        thisOplModel.o[i]=Opl.ftoi(Opl.round(cplex.getObjValue()));
        sum_o+=thisOplModel.o[i];
        thisOplModel.iter[i]=cplex.getNiterations();
        sum_iter+=thisOplModel.iter[i];
        writeln(i,"    ",thisOplModel.o[i],"     ",thisOplModel.iter[i],"       ",
        thisOplModel.d[i]/1000);
        cplex.clearModel();
    }    

    writeln("-----------------------------------------");
    writeln("average      ",sum_o/thisOplModel.n," ",
    sum_iter/thisOplModel.n," ",sum_d/thisOplModel.n/1000);
    writeln("std dev      ",Opl.standardDeviation(thisOplModel.o),"     ",
    Opl.standardDeviation(thisOplModel.iter),"     ",Opl.standardDeviation(thisOplModel.d)/1000);

    }

Upvotes: 0

Related Questions