Topic
  • 2 replies
  • Latest Post - ‏2014-05-21T10:00:16Z by Amani_Jerbi
Amani_Jerbi
Amani_Jerbi
7 Posts

Pinned topic Write a mathematical expression

‏2014-05-20T21:57:31Z |

Please how to write a mathematical expression or formula in OPL. I need to calculate the cost then use it in the objective function.

Do I write it in execute block ? 

Thanks.

  • AlexFleischer
    AlexFleischer
    1248 Posts

    Re: Write a mathematical expression

    ‏2014-05-21T08:46:57Z  

    Hi,

    you do not need any execute block for that. Let me give you a small example:

    dvar float+ Gas;
    dvar float+ Chloride;

    dexpr float objective=40 * Gas + 50 * Chloride;
    maximize objective;
     
    subject to {
      ctMaxTotal:     
        Gas + Chloride <= 50;
      ctMaxTotal2:    
        3 * Gas + 4 * Chloride <= 180;
      ctMaxChloride:  
        Chloride <= 40;
    }

    regards

  • Amani_Jerbi
    Amani_Jerbi
    7 Posts

    Re: Write a mathematical expression

    ‏2014-05-21T10:00:16Z  

    Hi,

    you do not need any execute block for that. Let me give you a small example:

    dvar float+ Gas;
    dvar float+ Chloride;

    dexpr float objective=40 * Gas + 50 * Chloride;
    maximize objective;
     
    subject to {
      ctMaxTotal:     
        Gas + Chloride <= 50;
      ctMaxTotal2:    
        3 * Gas + 4 * Chloride <= 180;
      ctMaxChloride:  
        Chloride <= 40;
    }

    regards

    Thank you so much.