Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Linear Optimization with (related) multiple constraints

    Dear all,

    While I am using Stata for many years I have never really worked with Mata. Now, I try to set up a linear optimization model for the first time. Despite reading through the manual, I am running into some (probably beginner's) questions.

    The (simplfied) model set-up is as follows:

    Code:
    Objective funtion:
    min(r_x1 * ∆ x1 + r_x2 * ∆ x2 - r_x3 * ∆x3)
    
    Constraints:
    ∆x1 + ∆x2 + ∆x3 = ∆y
    -∆x1 <= x1
    -∆x2 <= x2
    -∆x3 <= x3
    ∆x1 <= a
    ∆x1 + ∆x2 <= b
    L <= U - ∆x1 - ∆x2 + ∆y

    I started with programming this:

    Code:
    d_y = st_data(., ("d_y"))          
    
    x1 = st_data(., ("x1"))        
    x2 = st_data(., ("x2"))       
    x3 = st_data(., ("x3"))          
    
    r_x1 = st_data(., ("r_x1"))
    r_x2 = st_data(., ("r_x2"))
    r_x3 = st_data(., ("r_x3"))
    
    b = st_data(., ("a))       
    a = st_data(., ("b"))      
    
    // Objective function
    c = (r_x1, r_x2, -r_x3)
    
    // Restrictions
    Aec = (1 + 1 + 1)            
    bec = (d_y)
    
    // Bounds
    lowerbd = (-x1, -x2, -x3)   
    upperbd = ????
    The struggle begins for me already when I have multiple restrictions for the same variable.

    For now i have in particular the following questions:

    1. How do I define multiple constraints for the same variable? Do I use the J(.,.) function for that?
    2. How can I refer to other variables within the constraint of another variable? This would be necessary for ∆x1 + ∆x2 + ∆x3 = ∆y

    Any other comments or recommendations are also welcome.

    Thank you!

    Best wishes,
    Sebastian

  • #2
    In question 2. im meant the way to solve the inequality contraints ∆x1 + ∆x2 <= b of course. Sorry for the confusion.

    Comment


    • #3
      You'll need to give a minimal worked example. Maybe a simple dataset to illustrate what you want Mata to produce

      Comment

      Working...
      X