Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

3d array and 2d dvar doesn't work together?

  • 1.  3d array and 2d dvar doesn't work together?

    Posted Sat June 02, 2018 05:18 PM

    Originally posted by: StudentLucas


    I've simplified my problem:

    there are a 2d-array with article/price information and a 3d array with article/day/demand information

    The exercise is to get the best sales (combination of price and demand). But it doesnt work (there is "no solution"). If I change "==" to "<=" it works but with a wrong solution, the same is if I would use "=>".

    Hier is my code, could please somebody check it? Thanks in advance!

     

    {string} Fuel = {"Gasolin", "Diesel"};
    {string} Day = {"Monday", "Saturday"};
    
     // Index for price/demand category
     // 1: regular price, 2: discount price for members
    {int} I = {1, 2};
    
    int price[Fuel][I] = [
            [11, 8],
            [14, 10]
    ];
    
    int demand[Fuel][Day][I] = [
            [[100, 118],[221, 284]],
            [[122, 132],[319, 405]]
    ];
    
    dvar int+ sales[Fuel][Day];
    
    maximize sum(f in Fuel, d in Day) sales[f][d];
    
    subject to{
    
            forall(f in Fuel, d in Day, i in I){
                    sales[f][d] == price[f][i] * demand[f][d][i];
            }    
    }
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: 3d array and 2d dvar doesn't work together?

    Posted Sun June 03, 2018 02:13 AM

    Hi,

    {string} Fuel = {"Gasolin", "Diesel"};
    {string} Day = {"Monday", "Saturday"};

     // Index for price/demand category
     // 1: regular price, 2: discount price for members
    {int} I = {1, 2};

    int price[Fuel][I] = [
            [11, 8],
            [14, 10]
    ];

    int demand[Fuel][Day][I] = [
            [[100, 118],[221, 284]],
            [[122, 132],[319, 405]]
    ];

    dvar int+ sales[Fuel][Day];
    dvar boolean thisistheprice[Fuel][Day][I];

    maximize sum(f in Fuel, d in Day) sales[f][d];

    subject to{

    // for a given day and fuel, only one price

    forall(f in Fuel, d in Day) sum(i in I) thisistheprice[f][d][i]==1;


            forall(f in Fuel, d in Day){
                    sales[f][d] == sum(i in I) price[f][i] * thisistheprice[f][d][i]*demand[f][d][i];
            }    
    }

     

    will work better.

    regards

     

    https://www.linkedin.com/pulse/ist-mathematische-optimierung-und-wie-kann-sie-helfen-alex-fleischer/


    #CPLEXOptimizers
    #DecisionOptimization