Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

source_allocation code in cplex

  • 1.  source_allocation code in cplex

    Posted 04/01/13 06:48 PM

    Originally posted by: SystemAdmin


    Hey everyone, please can somebody help me in the following question:
    when I put index "temp_s" in the dvar boolean XVMserver , I get "cannot assign boolean for string"
    part of the code is mentioned below:

    The VM is string of 8 inputs and server is string of 13 input, but sources and destinations vary in requests and have 20 inputs and their inputs are VM's (source[1]="VM4" as an example, similarly for destination)
    forall(i in requests)
    {
    forall(q,c in server:q!=c)
    {
    forall(p in paths)
    {
    temp_s = sources[i];
    temp_d = destination[i];
    (3*Y[i][p]-(Xtemp_s[q]+Xtemp_d[q]+b[q][c][p]))<=0;
    }
    }
    }

    thanks a lot
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: source_allocation code in cplex

    Posted 04/01/13 07:17 PM

    Originally posted by: SystemAdmin


    Maybe the dvar dimension was not shown clearly in the previous post:
    The dvar X is two dimension VM server ;
    Similarly in the for loop;

    thanks
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: source_allocation code in cplex

    Posted 04/01/13 07:22 PM

    Originally posted by: SystemAdmin


    hi everyone !

    apparently , the problem is because i used the assignment operator = instead of == . but since the 2 variables are strings , it still doesnt work.
    is there a function to copy strings in CPLEX? like strcpy in C for example ? or do i have to go and copy them character by character?

    thanks
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: source_allocation code in cplex

    Posted 04/02/13 03:21 AM

    Originally posted by: SystemAdmin


    Hello,
    Could you also provide the part of the model where decision variables or expressions (temp_s, temp_d, sources, destination, Y, Xtemp_s, Xtemp_d) are defined ?

    Philippe
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: source_allocation code in cplex

    Posted 04/02/13 03:25 AM

    Originally posted by: ArnaudS


    Hi,

    It seems that you try to do scripting code (assign value to a temporary element "temp_s = sources[i];" )
    in the constraints block, which is not possible.
    You can do this only in an execute block.

    Regards,
    Arnaud
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: source_allocation code in cplex

    Posted 04/02/13 11:26 AM

    Originally posted by: SystemAdmin


    This is part of my code:

    {string} requests =...;
    {string} links =...;
    {string} VM=... ;
    {string} paths =...;
    {string} resources = ...;
    {string} sourcesrequests= ...;
    {string} destinationrequests = ...;
    {string} VM_no_node = ...;
    {string} VM_node = ...;

    string temp_s;
    string temp_d;
    int server_num = ...;
    int server_no_node = ...;
    int node_server = ...;

    range server_nonode = 1..server_no_node;
    range server_node = 11..node_server;
    range server = 1..server_num;

    int arequests,paths=... ;
    int bserver,server,paths=... ;
    int trequests=... ;
    int h =...;
    int rrequests=...;
    int Mserverresources=...;
    int KVMresources = ...;
    int TARD = ...;

    temp_s == first(sources);
    temp_d == first(destination);
    dvar int Strequests;
    dvar int XVM,server;
    dvar boolean Yrequests,paths;
    dvar boolean Wrequests,requests;

    minimize
    sum (rq in requests) (Strq-rrq) ;

    subject to {
    .....
    forall(i in requests)
    {

    forall(q,c in server:q!=c)
    {
    forall(p in paths)
    {
    temp_s = next(sources[i],temp_s);
    (3*Y[i][p]-(Xtemp_s[q]+Xtemp_d[q]+b[q][c][p]))<=0;
    temp_s = next(sources[i],temp_s);
    temp_d = next(destination[i],temp_s);
    }
    }

    }
    ....
    }

    I tried to use the first and the next method, but also it does not work,
    Is there any method in which I can assign a string value to another string?
    I need to vary term Xtemp_s[q] over the temp_s without using the forall, where temp_s will be one of the elements of the set of source that contains the VM.

    Thanks a lot
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 7.  Re: source_allocation code in cplex

    Posted 04/02/13 11:50 AM

    Originally posted by: SystemAdmin


    Hello,
    You get the error because you cannot use local variables (temp_s, temp_d) in the model declaration.

    If you want to post the constraint:
    
    (3*Y[i][p]-(X[temp_s][q]+X[temp_d][q]+b[q][c][p]))<=0;
    


    on set of pairs source/destination, you could create a tuple set of pairs <source,destination> from the data and do something like :

    
    tuple Request 
    { string id; string source; string destination; ... 
    }; 
    {Request
    } Requests = ...;   forall(r in Requests) 
    { forall(q,c in server: q!=c) 
    { forall(p in paths) 
    { (3*Y[r.id][p]-(X[r.source][q]+X[r.destination][q]+b[q][c][p]))<=0; 
    } 
    } 
    }
    


    Philippe
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 8.  Re: source_allocation code in cplex

    Posted 04/02/13 12:37 PM

    Originally posted by: SystemAdmin


    Thanks a lot Phillipe,
    It is working :),

    But still I get confused between using the OPL and writing a script?

    BR
    Manar
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 9.  Re: source_allocation code in cplex

    Posted 04/02/13 02:09 PM
    Hi
    Can you attach .mod and .dat ?
    Regards
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 10.  Re: source_allocation code in cplex

    Posted 04/03/13 05:27 PM

    Originally posted by: SystemAdmin


    Hello,

    I have attached the data file and in the next reply i will attach the mod file
    I run the code on my laptop, it gives no error but after an hour and half, it gave me: out of memory.
    So I run it again but on my desktop, it gives me an error:
    it did not accept the X http://r.source[q], similarly for the destination.
    I tried to change the tuple but it is not working,

    Thanks for the help,
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 11.  Re: source_allocation code in cplex

    Posted 04/03/13 05:28 PM

    Originally posted by: SystemAdmin


    The mod file is attached
    Note that in previous post, it is X http:// r . source q

    Thanks
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 12.  Re: source_allocation code in cplex

    Posted 04/05/13 12:57 PM

    Originally posted by: SystemAdmin


    Hey everyone I tried to run my code that I will be attached in this post, but I got the following error and I can not fix it?
    Does anybody know how to get rid of this error?

    Thanks
    Manar
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 13.  Re: source_allocation code in cplex

    Posted 04/05/13 12:58 PM

    Originally posted by: SystemAdmin


    In this post I put the .mod file
    Thanks
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 14.  Re: source_allocation code in cplex

    Posted 04/05/13 04:05 PM

    Originally posted by: ol


    Hello,
    the problem is that K, declared as an int array, contains two floating point values.
    If we replace them by integers, the first errors are solved, but then there are a lot of other errors. I let you advance in removing them, feel free to repost if you cannot find something.
    Regards,
    Olivier
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 15.  Re: source_allocation code in cplex

    Posted 04/19/13 02:08 PM

    Originally posted by: manar


    Hey everyone,

    I ahve tried to change some constraints in my code but when the number of requests in data is lower than 18, the cplex function normally as I increase the number of request to 20 and  above the cplex takes a long time and sometimes end up with out of memory problem. Also if i change the destination and source in the requests tuple or if I change the parameter t , the cplex take much more time even if i keep teh same number of requests. for instance , for 20 requests, for the initial dat it take 16 min to give output however for 20 requests amd different duration (t) or source or destination in tuple it will take 2,3 or more hours or even out of memeory case.

    So please can somebdoy tell me why this is happening and how can I solve it.

    I will upload the .dat . mod file


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 16.  Re: source_allocation code in cplex

    Posted 04/23/13 10:56 AM

    Originally posted by: manar


    Hello Everyone,

    Is there any problem in the way I wrote the codes attached in the previous post?

    Thanks

    Regards

    Manar


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 17.  Re: source_allocation code in cplex

    Posted 04/26/13 11:45 AM

    Originally posted by: ol


    Hello,

    you should try the following forums, where MIP specialists will more likely be able to help you to get a more efficient MIP formulation : https://www.ibm.com/developerworks/community/forums/html/category?id=33333333-0000-0000-0000-000000000261

    Regards,

    ol

     


    #DecisionOptimization
    #OPLusingCPOptimizer