Discussion: FAQ & hints: Assignment 2

No author
2022-11-17T12:52:00+01:00

Scoping of variables

T=150

# In order to change the value of T inside a for loop, you need to call global T

For Tvar in 50:30:200

global T = Tvar

# here you continue with your code

end

For exercise 2 and 3, you can create a for-loop where you update T according to above. However, you also need to rebuild the model each iteration. Otherwise, the model uses the old T and you will still solve the same problem.

Some hints on how to implement the model in Exercise 3

Below is some code help with the implementation of costs, and how to define the variable x with respect to the interval .

function build_model()
m = Model()

#create new cost matrix and cost function
cc = hcat(c, zeros(length(Components),1)) # use the same cost as before, but with added column for T+1
cits(i,s,t) = ( "if within life-time" ) ? (cc[i,t]) : ( "else let the cost be something else" )

# replace "if within life-time" and "else let the cost be something else" according to the article

@variable(m, x[Components, s in 0:T, t in s+1:T+1] >= 0) # here, s<t will always hold
@variable(m, z[1:T] >= 0, Bin)

...

end