Multiple dimensional sampling with first element string

x-ref: ArgumentError: invalid index: "s1" of type String

@GraceMabele you need to step back and re-consider what you are trying to do.

g = d -> @objective m Max begin
    sum((price[s]*d[s,n]) for n in N for s in S)
end

is a JuMP objective. it doesn’t make sense to try and fit a surrogate model to this, regardless of which method you chose.

It seems you really want something like

const S = ["s1","s2","s3","s4"]
const N = 1:10

const price = Dict(
    "s1" => 0,
    "s2" => 0,
    "s3" => 0,
    "s4" => 5
)

function objective(d::Matrix{<:Real})
    return sum(price[s] * d[i, n] for n in N for (i, s) in enumerate(S))
end

objective(rand(4, 10))  # Objective given a random demand

and now your take is to approximate objective given a 4x10 input matrix.

Here’s something to get you started

function objective(d::NTuple)
    return objective(reshape(collect(d), length(S), length(N)))
end

lb = fill(0.0, 40)
ub = fill(1.0, 40)
x_train = sample(10, lb, ub, SobolSample())
y_train = objective.(x_train)

However, I would again caution you. If you can write down the JuMP objective, why are you trying to fit a surrogate?

1 Like