Hey all,

I am trying to programm a simple optimization problem which minimizes the cost of a of an energy system with 4 suppliers subject to capacitiy constraints for 6 periods.

The costs are for each period are: costs = Dict(

“A” => [1.0,1.0,1.0,1.0,1.0,1.0],

“B” => [2.0,2.0,2.0,2.0,2.0,2.0],

“C” => [1.0,1.0,1.0,1.0,1.0,1.0],

“D” => [2.0,2.0,2.0,2.0,2.0,2.0],

)

The capacity contraints for each period are:

cap = Dict(

“A” => [1.0,2.0,1.0,0.0,0.0,0.0],

“B” => [2.0,1.0,2.0,0.0,0.0,0.0],

“C” => [0.0,0.0,0.0,1.0,2.0,1.0],

“D” => [0.0,0.0,0.0,2.0,1.0,2.0],

generator = keys(costs)

# Variables

@variable(dispatch_model, 0 <= y[generator],Int)

```
# Objective Function
@objective(dispatch_model,Min,
sum(costs[g]*y[g] for g in generator)
)
```

# capacity constraint:

@constraint(dispatch_model, cap[g in generator], (y[g] for g in generator) .<=cap[g] )

I could write the capacity constraint for each generator, like:

@constraint(dispatch_model, y[“A”].<= cap[“A”])

@constraint(dispatch_model, y[“B”].<= cap[“B”])

but I would prefer to only specify one constraint by looping through the cap dictionary, how do I achieve that in Julia?