Decision Optimization

 View Only
  • 1.  Variable naming issues.

    Posted Wed June 22, 2022 10:49 AM
    I name variables as x_0.1, x_0.2 ... but in LP file, it is x_0.1#1, x_0.2#2, etc. It happens with the latest version of CPLEX (not before).

    		ostringstream os_openpairStation;
    		os_openpairStation << "x_" << i << "." << j;
    		openPairStations[i][j].setName(os_openpairStation.str().c_str());​

    How could I solve this issue?



    ------------------------------
    Minh Vu
    ------------------------------


  • 2.  RE: Variable naming issues.

    IBM Champion
    Posted Wed June 22, 2022 11:19 AM
    You could replace "." with "_" in the variable name.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 3.  RE: Variable naming issues.

    Posted Wed June 22, 2022 11:42 AM

    Hi Paul,

    I did as your suggestion but it still shows #1, #2 ... in my variable names. 

    ​It also add _ before my "e" variables.

    + 535.5 x_1_2#28 + 425 x_1_3#29 + 72 x_1_4#30 - 10 _e_2_0#32
    - 8 _e_2_1#33 - 4.5 _e_2_2#34 - 4 _e_2_3#35 - 3.5 _e_2_4#36
    + 61 x_2_0#42 + 376 x_2_1#43 + 0 x_2_2#44 + 640 x_2_3#45
    + 46 x_2_4#46 - 3.5 _e_3_0#48 - 9 _e_3_1#49 - 5 _e_3_2#50
    - 4 _e_3_3#51 - 10 _e_3_4#52 + 171 x_3_0#58 + 420 x_3_1#59

    		for (int j = 0; j < info.numberStations; j++) {
    			ostringstream os_e;
    			os_e << "e_" << i << "_" << j; // empty vehicles
    			e[i][j].setName(os_e.str().c_str());
    		
    			ostringstream os_f;
    			os_f << "f_" << i << "_" << j; // full vehicles
    			f[i][j].setName(os_f.str().c_str());
    		
    			ostringstream os_openpairStation;
    			os_openpairStation << "x_" << i << "_" << j;
    			openPairStations[i][j].setName(os_openpairStation.str().c_str());
    		}​


    ------------------------------
    Minh Vu
    ------------------------------



  • 4.  RE: Variable naming issues.

    IBM Champion
    Posted Wed June 22, 2022 12:09 PM
    Hi Minh,

    I just tested this in Java (using both underscores and periods in variable names), and neither triggered the addition of the hash sign and index. So I suspect there is something C/C++ specific going on here. CPLEX appends the hash sign and an index to a variable or constraint name if it finds a character in the name that offends it (for being non-ASCII? non UTF-8?).  I wonder if the null-terminator in a "C-string" (which is what you are using) is the culprit. You might try converting the names to instances of std::string and see if that cures it. (This is one more reminder that I made a good choice abandoning C++ for Java.)

    Paul

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 5.  RE: Variable naming issues.

    Posted Thu June 23, 2022 07:56 PM
    Edited by Minh Vu Thu June 23, 2022 07:58 PM

    Thank you Paul,

    It seems that CPLEX does not have functions that support naming with a std::string parameter. Also, the output says:

    Warning: Output names have been modified due to duplicate names or characters invalid in LP format.

    budgetCons = IloRange(env, expr, info.maximumBudget_B, "budgetCons"); // it is also converted into budgetCons#123

    I only have constraints like above and the ones I mentioned before. 

    I do not have duplicate names, so the reason must be because of characters invalid in LP format.


    ------------------------------
    Minh Vu
    ------------------------------



  • 6.  RE: Variable naming issues.

    IBM Champion
    Posted Thu June 23, 2022 11:28 PM
    Given that a constant string ("budgetCons") triggers the warning, the only thing I can think of is the character encoding. Is it possible that your source code is using a character set other than ASCII? I think CPLEX accepts UTF-8 and maybe ISO-8859-1 as well as ASCII. There is a parameter that can be used to change the encoding for files read or written by CPLEX, but I doubt it applies to compiled C++ code. My Java code is written in us-ascii, and CPLEX has no problems with variable or constraint names, as long as I do not get too creative with the use of punctuation marks in the names.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------