Topic
16 replies Latest Post - ‏2013-04-26T15:44:38Z by ol
SystemAdmin
SystemAdmin
623 Posts
ACCEPTED ANSWER

Pinned topic source_allocation code in cplex

‏2013-04-01T22:48:19Z |
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
Updated on 2013-04-05T20:04:42Z at 2013-04-05T20:04:42Z by ol
  • SystemAdmin
    SystemAdmin
    623 Posts
    ACCEPTED ANSWER

    Re: source_allocation code in cplex

    ‏2013-04-01T23:16:56Z  in response to 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
  • SystemAdmin
    SystemAdmin
    623 Posts
    ACCEPTED ANSWER

    Re: source_allocation code in cplex

    ‏2013-04-01T23:22:27Z  in response to 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
    • SystemAdmin
      SystemAdmin
      623 Posts
      ACCEPTED ANSWER

      Re: source_allocation code in cplex

      ‏2013-04-02T07:21:13Z  in response to 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
    • ArnaudS
      ArnaudS
      8 Posts
      ACCEPTED ANSWER

      Re: source_allocation code in cplex

      ‏2013-04-02T07:24:48Z  in response to SystemAdmin
      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
      • SystemAdmin
        SystemAdmin
        623 Posts
        ACCEPTED ANSWER

        Re: source_allocation code in cplex

        ‏2013-04-02T15:25:32Z  in response to ArnaudS
        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
        • SystemAdmin
          SystemAdmin
          623 Posts
          ACCEPTED ANSWER

          Re: source_allocation code in cplex

          ‏2013-04-02T15:49:51Z  in response to 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
          • SystemAdmin
            SystemAdmin
            623 Posts
            ACCEPTED ANSWER

            Re: source_allocation code in cplex

            ‏2013-04-02T16:36:52Z  in response to SystemAdmin
            Thanks a lot Phillipe,
            It is working :),

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

            BR
            Manar
  • AlexFleischer
    AlexFleischer
    74 Posts
    ACCEPTED ANSWER

    Re: source_allocation code in cplex

    ‏2013-04-02T18:08:38Z  in response to SystemAdmin
    Hi
    Can you attach .mod and .dat ?
    Regards
    • SystemAdmin
      SystemAdmin
      623 Posts
      ACCEPTED ANSWER

      Re: source_allocation code in cplex

      ‏2013-04-03T21:26:53Z  in response to AlexFleischer
      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,
      • SystemAdmin
        SystemAdmin
        623 Posts
        ACCEPTED ANSWER

        Re: source_allocation code in cplex

        ‏2013-04-03T21:27:46Z  in response to SystemAdmin
        The mod file is attached
        Note that in previous post, it is X http:// r . source q

        Thanks
        • SystemAdmin
          SystemAdmin
          623 Posts
          ACCEPTED ANSWER

          Re: source_allocation code in cplex

          ‏2013-04-05T16:57:03Z  in response to 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
          • SystemAdmin
            SystemAdmin
            623 Posts
            ACCEPTED ANSWER

            Re: source_allocation code in cplex

            ‏2013-04-05T16:57:40Z  in response to SystemAdmin
            In this post I put the .mod file
            Thanks
          • ol
            ol
            19 Posts
            ACCEPTED ANSWER

            Re: source_allocation code in cplex

            ‏2013-04-05T20:04:42Z  in response to SystemAdmin
            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
            • manar
              manar
              2 Posts
              ACCEPTED ANSWER

              Re: source_allocation code in cplex

              ‏2013-04-19T18:08:11Z  in response to ol

              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

              Attachments