Adding Constraints
回答済み
Trying to add the following constraint, but keep getting TypeError: addConstrs() takes at least 2 positional arguments (1 given) error.
x = Decision variable, Binary variable, tupledict(loan, specname)
highballoanamt = continuous variable, tupledict(loan, specname) : LoanAmt for High Balance loans
loanamt = continuous variable, tupledict(loan, specname) : LoanAmt for all loans
What I am trying to achive is: For all the loans that got selected through optimizer, sum(HighBalLoanAmt) <= 0.20 * sum(LoanAmt)
hcfg = m.addConstrs(lhs = (x.prod(highballoanamt,'*', s) for s in specname
if (str.isnumeric(s) == False
and s.find('FG') != -1
and s.find('30') != -1)),
sense = GRB.LESS_EQUAL,
rhs = (0.20* x.prod(loanamt,'*', s) for s in specname
if (str.isnumeric(s) == False
and s.find('FG') != -1
and s.find('30') != -1)))
appreciate the help!
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Swapnil,
I would recommend finding the relevant elements in the specname list first. This should make constructing the constraint more readable.
Furthermore, addConstrs(generator, name) does not accept lhs, rhs, and sense parameters. These are used for the addConstr() method.
I hope that helps.
Cheers,
Matthias0 -
Thank you Matthias! let me try that, if you don't mind can you please point me to an example that has that construct? Thanks
0
投稿コメントは受け付けていません。
コメント
4件のコメント