Decision Optimization

 View Only
  • 1.  how to translate this code ????

    Posted Thu April 04, 2013 02:18 PM

    Originally posted by: SystemAdmin


    Hello ,
    I want to do something like this :
    //////////////////////
    int som= 0;
    for(int i=0;i<n;i++)
    {
    for(int j=0;j<m-1;m++)
    { som = som + ( x[i][0]*p[i][j] );
    }
    }
    ////////////////////

    where:
    x is IloNumVarArray
    p is an constant Array

    how can i do it ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: how to translate this code ????

    Posted Thu April 04, 2013 04:39 PM

    Originally posted by: SystemAdmin


    heeeeeeeelp please :-( :-(
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: how to translate this code ????

    Posted Fri April 05, 2013 05:19 AM

    Originally posted by: SystemAdmin


    Easy! This is not a commercial support Forum. People contribute to this forum when they have time. If you need quick reply and guaranteed response times to your requests then you need to obtain a commercial license. With that you can contact IBM customer support.
    Moreover, to get good and quick answer it is helpful to specify exactly what you want to, what you tried, what you expected and what did not work as expected. In your question it is not clear what you are trying to do (see my answer to your question).
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: how to translate this code ????

    Posted Fri April 05, 2013 05:22 AM

    Originally posted by: SystemAdmin


    What exactly do you want to do? I see at least the following two interpretations of your code:
    1. You want to create an expression that is the sum of x times p. In that case the type 'int' for 'som' does not make any sense.
    2. You want to compute the value of the sum of x times p. In that case you need to use IloCplex::getValue instead of x to get the value of the respective variable (note that values are only available if a feasible solution is available).
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  RE: how to translate this code ????

    Posted Tue October 31, 2023 09:53 AM

    To achieve the desired computation with the given arrays x and p, you can make use of nested loops as you've shown in your example. However, there's a minor typo in your code; in the inner loop, you should increment 'j' (the loop variable) instead of 'm-1'. Here's the corrected code snippet:
    int som = 0; for (int i = 0; i < n; i++) {
       for (int j = 0; j < m - 1; j++) { // Corrected 'm-1' to 'j'
         som = som + (x[i][0] * p[i][j]);
      }
    }
    This code will correctly calculate the sum (som) based on the elements of the arrays x and p.



    ------------------------------
    Earl Mitchell
    ------------------------------