Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Changing objective coefficients with CPXchgobj

    Posted 11/07/12 05:38 AM

    Originally posted by: SystemAdmin


    I am using CPLEX 12.3 on Windows XP to solve a set of LPs.
    The attached file (myprob_0.lp) is a LP model whose coefficients c2 and c6 are zeros. I use CPXchgobj to change the coefficients. Below is the code that is used for this purpose:
    
    
    
    double   *obj_value = 
    
    new 
    
    double[5];
    // Array of the new objective coefficients 
    
    int      *obj_index = 
    
    new 
    
    int[5];   
    // Array of the indices of the new objective coefficients   
    
    for (j=0; j < 5; j++) 
    { obj_value[j] = k(j); obj_index[j] = j; 
    }   status = CPXchgobj (env, lp, 5, obj_index, obj_value); 
    
    if (status) 
    { fprintf(stderr, 
    "Failed to change the objective coefficients.\n", status); system(
    "pause"); 
    }   status = CPXwriteprob (env, lp, 
    "myprob_1.lp", NULL); 
    
    if (status) 
    { fprintf(stderr, 
    "CPXwriteprob failed to write the LP Problem.\n", status); system(
    "pause"); 
    }
    

    The array k of the new coefficients cj is (1.12 0.87 176 5 3.6). After applying the change, the new objective function is obj: 1.12 u1 + 0.87 u3 + 176 u4 + 5 u5 + 3.6 v1
    The right coefficients are assigned to the wrong variables. This should be: obj: 1.12 u1 + 0.87 u2 + 176 u3 + 5 u4 + 3.6 u5
    Is there any possible reason for this?
    I appreciate your help.

    Amar
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Changing objective coefficients with CPXchgobj

    Posted 11/07/12 05:57 AM

    Originally posted by: T_O


    Do you create your problem by reading data from the lp-file? Then the order of the variables in the problem is (if I remember correctly) the same order in which the variables appear in the lp-file ( u1, u3, u4, u5, v1, ... ). So there is nothing wrong in your code, you just misinterpret some things.

    To avoid such problems, you could use mps or sav-files or set the objective coefficients by name.

    Best regards,
    Thomas
    #CPLEXOptimizers
    #DecisionOptimization