Skip to content

function calls with splatted variables not working within constraint() #258

Description

@jsphchoi

Can not use splatted ExaModel variables over colon inside function calls within constraint()

using ExaModels, MadNLP

V = 5
N = 10
K = 3

c = ExaCore()
z = variable(c, 1:V, 1:N, 0:K; start = 1.0)
h = exp10.(range(0,1,N))

# CASE 1: this works (expected)
itr_coll = [(i,k,h[i]) for i in 1:N, k in 1:K]
ftest(x...) = -x[1]*2 + x[2]*x[3] - x[4] + x[5]
constraint(c, -hi*ftest(z[1,i,k],z[2,i,k],z[3,i,k],z[4,i,k],z[5,i,k]) for (i,k,hi) in itr_coll)

# CASE 2: this works (expected)
itr_coll = [(i,k,h[i]) for i in 1:N, k in 1:K]
ftest2(x1,x2,x3,x4,x5) = -x1*2 + x2*x3 - x4 + x5
constraint(c, -hi*ftest2(z[1,i,k],z[2,i,k],z[3,i,k],z[4,i,k],z[5,i,k]) for (i,k,hi) in itr_coll)

# (IDEAL WORKING CASE) CASE 3: this doesn't work (not expected)
itr_coll = [(i,k,h[i]) for i in 1:N, k in 1:K]
ftest(x...) = -x[1]*2 + x[2]*x[3] - x[4] + x[5]
constraint(c, -hi*ftest(z[:,i,k]...) for (i,k,hi) in itr_coll)

# CASE 4: this doesn't work (not expected)
itr_coll = [(i,k,h[i]) for i in 1:N, k in 1:K]
ftest2(x1,x2,x3,x4,x5) = -x1*2 + x2*x3 - x4 + x5
constraint(c, -hi*ftest2(z[:,i,k]...) for (i,k,hi) in itr_coll)

######################################################
objective(c, (z[1,i,0] - 1)^2 for i in 1:N)
m = ExaModel(c)
madnlp(m)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions