Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Using Cplex for inter-temporal (mutiple time steps) optimization problem in Java!

  • 1.  Using Cplex for inter-temporal (mutiple time steps) optimization problem in Java!

    Posted 12/16/15 11:53 AM

    Originally posted by: SalmanKhan


    I wanted your help with solving an intertemporal electricity market clearing problem using CPLEX in Java.

     

    A brief description of my problem: I have 5 electricity generators.

     

    1.       Maximum generation capacity is fixed for all time steps.
    2.       The price at which they offer electricity is fixed for all time steps

     

    I want to minimize the marginal cost of overall generation against demand. My code is as follows:

    -------------------------------------------------------------------------------------------------------------------------------------------
    import ilog.concert.*;
    import ilog.cplex.*;

    public class LPex1 {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            model1();
        }

        public static void model1() {         
           
            double marginalCostGasPlant = 90.67;
            double marginalCostNuclearPlant = 40.98;
            double marginalCostCoalPlant = 50.44;
            double marginalCostWindPlant = 10.53;
            double marginalCostSolarPlant = 20.54;

            double maxGenerationCapacityGasPlant = 4000;
            double maxGenerationCapacityNuclearPlant = 2800;
            double maxGenerationCapacityCoalPlant = 5000;
            double maxGenerationCapacityWindPlant = 500;
            double maxGenerationCapacitySolarPlant = 1000;
           
            double maxSolarIrradiance = 0.6;
            double maxWindSpeed = 0.7;
           
            double availableWindCapacity = maxGenerationCapacityWindPlant * maxWindSpeed;
            double availableSolarCapacity = maxGenerationCapacitySolarPlant * maxSolarIrradiance;
           
            double totalDemand = 1000;

            System.out.println("Starting optimization model");
            System.out.println("Available wind capacity is: "+availableWindCapacity);
            System.out.println("Available solar capacity is: "+availableSolarCapacity);
           
            double mTotalDemand = totalDemand;

            try {
                IloCplex cplex1 = new IloCplex();

                // defining variables

                IloNumVar generationCapacityGasPlant = cplex1.numVar(0, maxGenerationCapacityGasPlant,
                        "generationCapacityGasPlant");
                IloNumVar generationCapacityNuclearPlant = cplex1.numVar(0, maxGenerationCapacityNuclearPlant,
                        "generationCapacityNuclearPlant");
                IloNumVar generationCapacityCoalPlant = cplex1.numVar(0, maxGenerationCapacityCoalPlant,
                        "generationCapacityCoalPlant");
                IloNumVar generationCapacityWindPlant = cplex1.numVar(0, availableWindCapacity,
                        "generationCapacityWindPlant");
                IloNumVar generationCapacitySolarPlant = cplex1.numVar(0, availableSolarCapacity,
                        "generationCapacitySolarPlant");

                // defining expressions

                IloLinearNumExpr objective1 = cplex1.linearNumExpr();
                objective1.addTerm(marginalCostWindPlant, generationCapacityWindPlant);
                objective1.addTerm(marginalCostSolarPlant, generationCapacitySolarPlant);
                objective1.addTerm(marginalCostGasPlant, generationCapacityGasPlant);
                objective1.addTerm(marginalCostNuclearPlant, generationCapacityNuclearPlant);
                objective1.addTerm(marginalCostCoalPlant, generationCapacityCoalPlant);

                // defining objective

                cplex1.addMinimize(objective1);

                // defining constraints

                IloLinearNumExpr constraint1 = cplex1.linearNumExpr();
                constraint1.addTerm(1, generationCapacityWindPlant);
                constraint1.addTerm(1, generationCapacitySolarPlant);
                constraint1.addTerm(1, generationCapacityGasPlant);
                constraint1.addTerm(1, generationCapacityNuclearPlant);
                constraint1.addTerm(1, generationCapacityCoalPlant);

                cplex1.addEq(constraint1, mTotalDemand);

                cplex1.addGe(maxGenerationCapacityGasPlant, generationCapacityGasPlant);
                cplex1.addGe(maxGenerationCapacityNuclearPlant, generationCapacityNuclearPlant);
                cplex1.addGe(maxGenerationCapacityCoalPlant, generationCapacityCoalPlant);
                cplex1.addGe(availableWindCapacity, generationCapacityWindPlant);
                cplex1.addGe(availableSolarCapacity, generationCapacitySolarPlant);

                cplex1.setParam(IloCplex.IntParam.Simplex.Display, 0);

                // solve

                if (cplex1.solve()) {
                    System.out.println("Objective = " + cplex1.getObjValue());
                    System.out.println("Objective = " + cplex1.getStatus());

                    System.out.println("generationCapacityGasPlant = " + cplex1.getValue(generationCapacityGasPlant));
                    System.out.println("generationCapacityNuclearPlant = " + cplex1.getValue(generationCapacityNuclearPlant));
                    System.out.println("generationCapacityCoalPlant = " + cplex1.getValue(generationCapacityCoalPlant));
                    System.out.println("generationCapacityWindPlant =  " + cplex1.getValue(generationCapacityWindPlant));
                    System.out.println("generationCapacitySolarPlant =  " + cplex1.getValue(generationCapacitySolarPlant));
                    System.out.println("TotalGeneration =  " + cplex1.getValue(constraint1));

                } else {
                    System.out.println("Something went wrong");
                }

                cplex1.end();

            } catch (IloException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
         }
    }

    This is for just one time step. I want to clear the market for multiple time steps. For that I would need to minimize a whole matrix with many linearNumExpr rather then just one. I would really appreciate if you can help me out here. I am looking into the addminimize function but it doesn't take matrices or arrays as input. Further more, how can I assign linear num exprs to matrix locations?

     Thanks


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Using Cplex for inter-temporal (mutiple time steps) optimization problem in Java!

    Posted 01/05/16 03:41 AM

    I think we resolved the issues offline. Please come back if you still have trouble.


    #CPLEXOptimizers
    #DecisionOptimization