1

variables:

    set I:={1..4}; # prod 1-4
    var x{I} >=0 integer; # Set this to a non-negative number!
    var y{I} binary;  # Fixed cost is no matter what!

Constraints: #Profit #I have tried this and it does work: however I want to make it cleaner with less duplicate code.

    #s.t. p1: x[1] <= y[1]*Profit[1];
    #s.t. p2: x[2] <= y[2]*Profit[2];
    #s.t. p3: x[3] <= y[3]*Profit[3]; 
    #s.t. p4: x[4] <= y[4]*Profit[4];

not pretty but it works. I want to iterate through the list {i in I} to make it cleaner.

I have tried These and they do not work.

    s.t. pRofit: for{i in I}{ x[i]} <= for{i in I}{ y[i] * Profit[i]};
    s.t. pRofit: sum{i in I}{ x[i]} <= sum{i in I}{ y[i] * Profit[i]};

Does AMPL offer a for loop solution?

I have tried These and they do not work.`

    s.t. pRofit: for{i in I}{ x[i]} <= for{i in I}{ y[i] * Profit[i]};
    s.t. pRofit: sum{i in I}{ x[i]} <= sum{i in I}{ y[i] * Profit[i]};

    * even tried the suggested stackO solutions:
    s.t. c1{i in S}: x[i] = y[i]*Profit[i]; by: GB supports the mod strike.

Does AMPL offer a for loop solution?

1 Answer 1

1

So I posted the question and forgot, using cplex;

also went back and tried it again and boom this worked.😂

 s.t. pRofit{i in I}: x[i] <=  y[i] * Profit[i];  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.