Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  beginner in cplex, rand

    Posted 08/28/18 12:01 AM

    Originally posted by: csfab


    Dear, all right.

    My name is Fernando, and I live in Brazil, and I am just getting into the use of CPLEX, I, along with my students, are doing a work based on the traveling salesman with 1500 points.

    We have an array of distances of 1500x1500 and we want to sort out a coordinate point (row, column) and calculate the shortest distance to that point given a starting point.

    We're not getting the rand function to work.

    Thank you.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: beginner in cplex, rand

    Posted 08/28/18 03:16 AM

    Hi,

    a few starting points for TSP : https://www.ibm.com/developerworks/community/forums/html/topic?id=f58daf79-f752-48e4-8f25-54b2f6f71b40&ps=25

    some how to in OPL https://www.linkedin.com/pulse/how-opl-alex-fleischer/

    plus https://www.linkedin.com/pulse/o-que-%C3%A9-otimiza%C3%A7%C3%A3o-e-como-isso-pode-ajud%C3%A1-lo-fazer-mais-fleischer/

    For rand, you have an example in the OPL documentation:

    int r1[i in 1..10]=rand(10);
    int r2[i in 1..10]=rand();

    execute
    {
     writeln("int r1[1..10]=rand(10) gives ",r1);  
     writeln("int r2[1..10]=rand() gives ",r2);

    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: beginner in cplex, rand

    Posted 08/29/18 11:14 AM

    Originally posted by: csfab


    Hello, Alex, how are you?

    So, I had already seen the manual but could not get it to work:

    Here's the template I'm working on:

     

     

    //Parâmetros

    int n = 100;
    range cidades = 1..n;
    float x[cidades];
    float y[cidades];
    float distancias[cidades][cidades];

     

    1) I want to sort a distance from the distance matrix

     

     

    float destino[cidades][cidades] = rand(distancias); 

     

     

     

    //Pré-processamento
     
    execute DADOS{
    function calcdistancia(cidadea,cidadeb){
    return Opl.sqrt(Opl.pow(x[i]-x[j], 2)+ Opl.pow(y[i]-y[j], 2));
     
    }
     
     
    for (var c in cidades){
    x[c]=Opl.rand(2000);
    y[c]=Opl.rand(2000);
    writeln ("cidade" + ' '+c+": ("+x[c]+','+y[c]+")");}
     
    for (var i in cidades)
    for (var j in cidades)
    if (i!=j){
    distancias[i][j]=calcdistancia(i,j);
    if (j>i){
    writeln ("A distância entre a cidade"+' '+i+' '+"e a cidade"+ ' ',j+ ' '+ "é de "+' '+distancias[i][j]+ ' '+"km");
    }
    }
    }
     
    //Variáveis de decisão
    dvar boolean rota[cidades][cidades];
    dvar float+ u[cidades];
     
    //Expressões
    dexpr float caminho = sum(i in cidades, j in cidades: i!=j) distancias[i][j]*rota[i][j];
     
    //Função objetivo
    minimize
      caminho;
     
    //Restrições
     
    subject to{
     
    flowing:
    forall (j in cidades)
      sum(i in cidades: i!=j) rota[i][j]==1;
      
    flowout:
    forall (i in cidades)
      sum(j in cidades: i!=j) rota[i][j]==1;
      
    ESubrotas:
    forall (i in cidades, j in cidades: i>1 && j>1 && i!=j)
      u[i]-u[j] + n*rota[i][j] <= n-1;
     
     
    }
     

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: beginner in cplex, rand

    Posted 08/29/18 11:30 AM

    Hi,

    what about

    //Parâmetros
    int n = 100;
    range cidades = 1..n;
    float x[cidades];
    float y[cidades];
    float distancias[cidades][cidades];

     


    //Pré-processamento
     
    execute DADOS{
    function calcdistancia(cidadea,cidadeb){
    return Opl.sqrt(Opl.pow(x[i]-x[j], 2)+ Opl.pow(y[i]-y[j], 2));
     
    }
     
     
    for (var c in cidades){
    x[c]=Opl.rand(2000);
    y[c]=Opl.rand(2000);
    writeln ("cidade" + ' '+c+": ("+x[c]+','+y[c]+")");}
     
    for (var i in cidades)
    for (var j in cidades)
    if (i!=j){
    distancias[i][j]=calcdistancia(i,j);
    if (j>i){
    writeln ("A distância entre a cidade"+' '+i+' '+"e a cidade"+ ' ',j+ ' '+ "é de "+' '+distancias[i][j]+ ' '+"km");
    }
    }
    }

     

    float destino[c1 in cidades][c2 in cidades] = rand(ftoi(ceil(distancias[c1][c2])));

     

     

     

     
    //Variáveis de decisão
    dvar boolean rota[cidades][cidades];
    dvar float+ u[cidades];
     
    //Expressões
    dexpr float caminho = sum(i in cidades, j in cidades: i!=j) distancias[i][j]*rota[i][j];
     
    //Função objetivo
    minimize
      caminho;
     
    //Restrições
     
    subject to{
     
    flowing:
    forall (j in cidades)
      sum(i in cidades: i!=j) rota[i][j]==1;
     
    flowout:
    forall (i in cidades)
      sum(j in cidades: i!=j) rota[i][j]==1;
     
    ESubrotas:
    forall (i in cidades, j in cidades: i>1 && j>1 && i!=j)
      u[i]-u[j] + n*rota[i][j] <= n-1;
     
     
    }

    ?

     

    regards

     

    https://www.linkedin.com/pulse/o-que-%C3%A9-otimiza%C3%A7%C3%A3o-e-como-isso-pode-ajud%C3%A1-lo-fazer-mais-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: beginner in cplex, rand

    Posted 08/29/18 12:53 PM

    Originally posted by: csfab


    It's a TSP template, which I'm adapting.

    In which I have an array of 1400 rows and 1400 columns.

    Within this matrix I have a coordinate that is the origin and I want to get to another point that is the destination.

    Then the model will calculate the smallest path from source to destination.

    Maybe we'll use another model.

    Thank you.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer