I believe it would be good to add to the error messages for the @constraints macro, to draw attention to the fact that a valid input for @constraint is not a valid input for @constraints. This is a mistake that is easy to make and hard to spot, but could be remedied by changing the error message or what constitutes a valid input for @constraints.
The @constraints macro allows one to write out multiple lines of contraints in a block, and returns a tuple of the constraints. This is great and I like using it as it aids readability.
Unfortunately, if one tries to treat @constraints like @constraint (without the s), Julia returns an unhelpful error.
For example: running this code gives an error. ERROR: LoadError: Invalid syntax for @constraints
using JuMP, GLPK
# Preparing an optimization model
model = Model(GLPK.Optimizer)
# Declaring variables
@variable(model, x >= 0)
# Setting the objective
@objective(model, Min, x)
@constraints(model, 2x <= 1)
# Printing the prepared optimization model
print(model)
It is easy to disregard the âsâ at the end of the constraints macro, and when doing so the error message given is not particularly helpful.
If you try editing the above code to use @constraint instead of @constraints, it runs correctly.
I am a newcomer to this language so I am hesitant to start by making a pull request. Let me know if this seems like a fair change to make.
One more suggestion, when using JuMP, it does not have code hints for the variables I define, which may cause me to forget some of the variables I have defined when I define many of them. If code hints are available, this problem can be solved. However, variables are defined by macros, and I do not know if there is a solution to this problem.
Sorry to make you confused, let me give an example to explain:
nNum = 10
@variable(model, test[1:nNum] >= 0)
I define a variable test and a parameter nNum above, when I add constraints below and I donât get prompted for the variable I defined called âtestâ, but I do get prompted for the parameter called ânNumâ. For example, when I type in ânNâ, ânNumâ gets prompted, but âtestâ does not unless I type in the full characters.
Is this in VS-Code? I can reproduce for test, but I canât reproduce in general:
I think the issue is that test is too common, to the heuristic for what names to show doesnât kick in? Regardless, this seems like an issue in VS-Code, not in JuMP.