Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Error: can not convert to a number

    Posted 11/26/18 02:49 PM

    Originally posted by: Margarett


    Hello! 

    Below is the code. Data is exported from Microsoft Access to CPLEX.

    I am using IBM ILOG CPLEX Optimization Studio 12.6.1.0. 


    I need to export data as an array (!).
    Then I need to summ up the arrays:

    Result[i]=d[i]+Mas[i], i=1..3 , id est

    0.6+1.4 = 2

    0.8+2.4 = 3.2

    0.5+3.4 = 3.9

     

    In the .mod file, I wrote:

    {int} a=...;

    tuple demand  {
     int a;
     float value; }

    demand d[a]=...;

    range R = 1..3;
    float Result[R];
    float Mas[R]=[1.4, 2.4, 3.4];

    execute {
    for(var i in R) {
    Result[i] = d[i] + Mas[i];
    }}

     

    In the .dat file, I wrote:

    DBConnection db("access","test.mdb");
    a,d from DBRead(db,"SELECT a,a,v FROM Prob");

     

    (?) I have error in calculating the amount : "can not convert to a number". 

    Please tell me how to correct the code to calculate the sum of arrays?

     

     

    Best regards, 

    Margarett. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Error: can not convert to a number

    Posted 11/27/18 02:44 AM

    Hi

    {int} a={1,2,3};

    tuple demand  {
     int a;
     float value; }

    demand d[a]=[<1,2.0>,<2,3.4>,<3,3.4>];;

    range R = 1..3;
    float Result[R];
    float Mas[R]=[1.4, 2.4, 3.4];

    execute {
    for(var i in R) {
    Result[i] = d[i].value + Mas[i];
    }}

    works fine

    regards

    https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Error: can not convert to a number

    Posted 11/27/18 03:06 AM

    The error seems pretty clear. In this line

    Result[i] = d[i] + Mas[i];

    you are trying to add a tuple (d[i]) and a float (Mas[i]). What is that supposed to mean? I guess instead of the tuple d[i], you want one of its fields? Either d[i].a or d[i].value?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Error: can not convert to a number

    Posted 11/27/18 01:47 PM

    Originally posted by: Margarett


    Alex, thanks! It really works fine. 

    Daniel, I needed to use: "d[i].value".  But I didn't know that I can use the dot operator ( .value ).  Thanks, I figured it out now! 

     

    Please, can I ask one more question? The previous question is part of my task.

    I export data from Matlab to Microsoft Access. Then I import the data from Microsoft Access into CPLEX.

    But unfortunately there is a problem in the export of data from Matlab.

    Please, could you see what my mistake is.

     

    Below is the code for the task:

    • matrix "Q" with a dimension of 3*2 was obtained using a matrix of cells "A";
    • then the matrix "Q" is exported to Microsoft Access with the same dimension (3 rows, 2 columns).

    (!) The difficulty is that only the first row of the matrix is written to Microsoft Access (of the three available) and then an error message is displayed:

    • Error using database/insert (line 213) General error
    • Error in test_matlab (line 22) insert(conn, 'Rtu', colnames, Q);

    (?) Please, tell me, how is it necessary to add / correct the code in order to record all three rows of the matrix in Microsoft Access?

     

    Q=[];
    A={1, [3 5 8]} % array of cells

    for j=1:2 % matrix column index
    for i=1:3 % matrix row index
    if j==1
    Q(i,j)=A{1,j};
    else 
    Q(i,j)=A{1,j}(1,i);
    end
    end
    end

    Q

    conn = database('QWERT', '', '');
    colnames = {'u1', 'u2'};

    insert(conn, 'Rtu', colnames, Q);
    close(conn);

     

    Matlab version is R2014b.

    Below there is an archive with files.

     

    Best regards, 

    Margarett. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Error: can not convert to a number

    Posted 11/27/18 03:10 PM

    Uhm, this is clearly a problem with matlab or Access, right? So you are probably better of in a forum that is dedicated to using Access from matlab.

    What I wonder is this: do you need the detour via Access? Can't you just write csv or even plain .dat files from matlab and then import those directly into CPLEX?

    In any case, your code looks pretty different from the examples on these pages:

    https://de.mathworks.com/help/database/ug/database.odbc.connection.insert.html;jsessionid=6cd3c51c9021ef748793b566ad3c

    https://de.mathworks.com/help/database/ug/database.odbc.connection.datainsert.html

    Maybe double check with these pages whether your code is correct. Also the insert() function is deprecated. Apparently one should use sqlwrite(). Maybe that works better for you?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Error: can not convert to a number

    Posted 11/28/18 11:47 AM

    Originally posted by: Margarett


    Daniel, thanks! 

    Yes, I wrote on the 6 forums that is dedicated to using Access from matlab. But no one could answer. 

    Today I found the cause of this error.

    The code was correct. 
    The problem was in the settings of Microsoft Access. 

    It was necessary to specify in the settings of Microsoft Access "Сoncordance of Elements are allowed". 

    Before this was specified in the settings "Сoncordance of Elements are not allowed".

    In result, the program began to work correctly after changing the settings. 

     

    Daniel, thank you very much for your answers! 

     

    Best regards, 

    Margarett. 


    #CPLEXOptimizers
    #DecisionOptimization