2

I need to transform a AMPL code to JuMP.

param f;

set R := 1..N;
set R_OK := 1..M;
set V := 1..N;

param tMax;
set T := 1..tMax;

var primary{R,V}, binary;
var SendPrepReq{T,R,V}, binary;

"param f" would be an int. The varibles I know how to do. But what about the sets? What is its equivalent in JuMP?

bakun
  • 448
  • 1
  • 9
  • 17

1 Answers1

1

One of the most relevant pieces of documentation may be the Quickstart guide to get the basics of how JuMP works.

For your example, you can just declare your parameters directly:

using JuMP

# declare some parameters
f = 3
N = 10
M = 5
R = 1:N
V = 1:N
R_OK = 1:M

Tmax = 33
T = 1:Tmax

# create the model
m = Model()
# add variables
@variable(m, primary[R,V], Bin)
@variable(m, SendPrepReq[T,R,V], Bin)

EDIT

One might want to provide parameters independently from the model declaration as in AMLP. The most straightforward way in Julia will be to build and solve the model in a function taking the problem parameters in argument:

function build_model(f, N, M, Tmax)
    R = 1:N
    V = 1:N
    R_OK = 1:M
    T = 1:Tmax

    # create the model
    m = Model()
    # add variables
    @variable(m, primary[R,V], Bin)
    @variable(m, SendPrepReq[T,R,V], Bin)

    return (m, primary, SendPrepReq)
end
Mathieu B
  • 451
  • 3
  • 12
  • parameters are just simple variables as in other programming languages. If you want to given them values later, the simplest way will be to put the optimization in a function with the parameters as arguments – Mathieu B Mar 13 '20 at 15:57
  • Would it be right to say that " var prepReqSendPerNodeAndView{R,V}, integer, >= 0; " would be " @varible(m, prepReqSendPerNodeAndView[R,V] >=0, Int) " – bakun Mar 24 '20 at 14:00
  • Yes that's correct, watch out for the typo in `@variable` – Mathieu B Mar 25 '20 at 15:03
  • In the AMPL code, there is a parte called "Time zero constraints", and they are like: "initializeSendPrepareReq{i in R, v in V}: SendPrepReq[1, i, v] = 0;" and "initializeRecvCV{i in R, j in R, v in V}: RecvCV[1, i, j, v] = 0;" I got some ideia from the guide, but I don't know how to do these. – bakun Mar 29 '20 at 16:56
  • That would correspond to fixing a variable to a value, which is done in JuMP with the fix function: JuMP.fix(SendPrepReq[1, i, v], 0) – Mathieu B Mar 30 '20 at 17:09
  • Thanks, but didn't you forget to define "i" and "v" before the fixing? In the original code says "i in R" and "v in "V" before the SendPrepReq[1, i, v] = 0; – bakun Apr 01 '20 at 18:16