Python pulp error when exporting a problem to json file. #419
Unanswered
moheikal79
asked this question in
Q&A
Replies: 2 comments 3 replies
-
That's interesting. It's possible there's an error in export function (or your model has something we did not expect). Do you have a reproducible example we can test to find the source of the problem? |
Beta Was this translation helpful? Give feedback.
3 replies
-
In fact, I do not like using pandas with pulp. Nevertheless, I know many
people use it since it's easy to pass from tables to model.
I think we had envisioned a "best practices" page somewhere in the docs. We
should one day put something about that.
F.
…On Tue, Mar 30, 2021, 18:58 moheikal79 ***@***.***> wrote:
Thanks for reply, I have used option 1 and added int() to all constraints
and the step of adding variables to the model, and it works fine. It will
be a great step to include examples of using pandas along with pulp as they
are used together in production. I am attaching the code after resolving
the issue.
pulp+json.txt
<https://github.com/coin-or/pulp/files/6230785/pulp%2Bjson.txt>
Regards
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#419 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJUZ46XFB4RCNPEP2J5FQLTGH7MJANCNFSM4Z5AWO4A>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Please for advice, I am facing a problem when exporting a python pulp problem to json file "-75 is not JSON serializable".
variables= pulp.LpVariable.dicts("x", (item for item in df.index), lowBound=0, cat='Integer')
model = pulp.LpProblem("Nova_2_levels_maximize", LpMaximize)
model += pulp.lpSum([variables[item] * df.loc[item, 'Profitability'] for item in df.index])
max_weight = 500000
model += pulp.lpSum([variables[item] * df.loc[item, 'Weight'] for item in df.index]) <= max_weight
max_size = 100000
model += pulp.lpSum([variables[item] * df.loc[item, 'Size'] for item in df.index]) <= max_size
min_sales = 4000
model += pulp.lpSum([variables[item] * df.loc[item, 'Sales price'] for item in df.index]) >= min_sales
min_qty = df.index
for nq in min_qty:
model += variables[nq] >= df.loc[nq, 'Min Qty sales']
max_qty = df.index
for xq in max_qty:
model += variables[xq] <= df.loc[xq, 'Max Qty sales']
model.solve()
model.to_json(r"D:\PL\test.json")
Beta Was this translation helpful? Give feedback.
All reactions