Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Export results to c programming

    Posted 07/29/12 11:43 PM

    Originally posted by: iturkmen


    Hi,
    I am using C programming. I have decision variables like y(i,j,k,t). I solved my problem and assume that my solution looks like this:
    y(1,1,6,185) = 0.196002
    y(1,1,9,3047) = 0.242096
    y(1,1,10,2761) = 0.334921
    y(1,1,11,2951) = 0.226982
    y(1,5,10,2601) = 0.196002
    y(1,6,7,636) = 0.196002
    y(1,7,8,1228) = 0.196002

    I wrote these variables to the *.txt file with this code:
    for (i1 = 0; i1 < numDecVars; i1++) {
    if (x_solni1 > 0) {
    fprintf(dec_var_name_file, " %s = %lf \n", decVarNamei1, x_solni1);
    }
    }

    I need to add these variables to my original problem as additional constraints. However I couldn't find a way to read the file with parentheses. Is there any way to write the decision variables without parenthesis? or Is there any way to create c code for ignore the parentheses?

    Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Export results to c programming

    Posted 07/31/12 04:26 AM

    Originally posted by: SystemAdmin


    How did you try to read the txt file? Could you show us the code that failed and tell us what exactly failed? I don't see why the parentheses should cause any trouble when reading the file.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Export results to c programming

    Posted 07/31/12 04:58 PM

    Originally posted by: iturkmen


    Hi,
    My code includes these :

    strcat(infile, "/mydata.txt");
    sscanf(Line, "%s %d,%d,%d,%d %s %lf",&Y1, &V1, &I1, &J1, &T1, &N2,&Val);

    It doesn't work because I don't know how to code this situation.

    My decision variables are listed below.
    y(1,1,6,185) = 0.196002
    y(1,1,9,3047) = 0.242096
    y(1,1,10,2761) = 0.334921

    I 'd like to have a matrix or arrays like this, I am not sure that I can do this.

    M=[1, y, 1, 1, 6, 185, 0.196002 ;
    2, y, 1, 1, 9, 3047, 0.242096;
    3, y, 1, 1 ,10, 2761, 0.334921]
    Actually I want to store string y as a decision variable name,and i,j,k,t as indices and decision variable value. When I store these data in arrays, I will rank them according to the decision variable values. Lastly, I will add the highest decision variable as additional constraint to my original model.

    Thanks for your help.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Export results to c programming

    Posted 08/01/12 03:30 AM

    Originally posted by: SystemAdmin


    Still not sure I understand correctly. Is your problem to read/parse a text file in C?
    A file with this content
    
    y(1,1,6,185) = 0.196002 y(1,1,9,3047) = 0.242096 y(1,1,10,2761) = 0.334921
    

    can be parsed by the following code snippet
    
    #include <stdio.h> #include <string.h>   
    
    int main(
    
    void) 
    { FILE *f; 
    
    char y; 
    
    int i, j, k, l; 
    
    double val; 
    
    char line[1024]; 
    /* Assume no line is longer than 1024 characters. */   
    
    if ( (f = fopen(
    "mydata.txt", 
    "r")) == NULL ) 
    { perror(
    "fopen"); 
    
    return -1; 
    }   
    
    while (fgets(line, sizeof(line), f) != NULL) 
    { 
    
    if (sscanf(line, 
    "%c(%d,%d,%d,%d) = %lf\n", &y, &i, &j, &k, &l, &val) == 6) 
    { printf(
    "%c[%d][%d][%d][%d] = %f\n", y, i, j, k, l, val); 
    } 
    }   fclose(f);   
    
    return 0; 
    }
    

    #CPLEXOptimizers
    #DecisionOptimization