Decision Optimization

 View Only
Expand all | Collapse all

Problems at creating "IloNumVar"

  • 1.  Problems at creating "IloNumVar"

    Posted Thu September 26, 2013 09:04 PM

    Originally posted by: mvp2236


    Hi,

    I implemented a source code like this:

     

    #pragma once

    #include <iostream>
    #include <stdio.h>
    #include <cstdlib>
    #include <ilcplex/ilocplex.h>
    #define BS 3
    #define MS 5
     
     
    using namespace std;
     
    IloEnv env;
    IloModel model(env);
    IloNumVarArray vars(env),Vars(env);
    IloNumArray Coes(env),vals(env);
    IloCplex cplex (model);
     
    void main ()
     {
      int i,j;
     
      double *Y_min;   
      double *Y_max;      
      Y_min = new double [BS]; 
      Y_max = new double [BS];
                 
      for(i=0; i<BS; i++){
        Y_min[i] = 0.0;
       Y_max[i] = 1.0;
       vars.add(IloNumVar(env, Y_min[i], Y_max[i]));
       }
     
          
         double *x_min;   
         double *x_max;
         x_min = new double [BS*MS];
         x_max = new double [BS*MS];
     
        for(int i = BS;i<BS+BS*MS ;i++){
          x_min[i] = 0.00;
          x_max[i] = 1.00;
           vars.add(IloNumVar(env,x_min[i], x_max[i]));
      }
     
     
    double * P_d_min;   
    double * P_d_max;
    P_d_min = new double [MS*BS];
    P_d_max = new double [MS*BS];
     
     for(int i=BS+BS*MS ;i<BS+2*BS*MS;i++){
      P_d_min[i] = 0.0;
      P_d_max[i] = 40.0;
      vars.add(IloNumVar(env, P_d_min[i], P_d_max[i]));
         }
     
     
    double * S_d_min;   
    double * S_d_max;
    S_d_min = new double [MS*BS];
    S_d_max = new double [MS*BS];
     
    for(int i=BS+2*BS*MS ;i<BS+3*BS*MS ;i++){
         S_d_min[i]=0;
         S_d_max[i]=20.0;
         vars.add(IloNumVar(env, S_d_min[i],S_d_max[i]));
    }
     
    env.end();
    }

     

    This code  is to create variables in IloEnv env and it has been compiled successfully. But I can not do this.

    Could you help me?


    Thank you.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problems at creating "IloNumVar"

    Posted Fri October 04, 2013 12:04 PM

    Please tell us what exactly your problem is. Do you get an exception? Does the program crash? What is the line that causes trouble?

    At first glance I see at least one problem that is completely unrelated to CPLEX:

         x_min = new double [BS*MS];
         x_max = new double [BS*MS];
     
         for(int i = BS;i<BS+BS*MS ;i++){
            x_min[i] = 0.00;
            x_max[i] = 1.00;
            ...
         }

    This initializes x_min and x_max to be arrays with BS*MS elements. The loop then runs until i=BS+BS*MS-1, that is, it will perform an index out of bounds access into the x_min and x_max arrays. This is likely to crash your program. Similar problems exist with other arrays in your program. Double check all array sizes and array accesses.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problems at creating "IloNumVar"

    Posted Mon October 07, 2013 06:52 AM

    Originally posted by: mvp2236


    Hi,

    Firstly, I would like to thank you for your reply. I will  double check   all array sizes and array accesses.
     


    #CPLEXOptimizers
    #DecisionOptimization