Hot answers tagged

12

To get the value of the decision variable, you need to use the varValue property of the LpVariable, so: print(x.varValue) You can also use: print(x.value()) The explanation is that the Python variable x is not the decision variable itself, it is a PuLP object of type LpVariable: In[5]: type(x) Out[5]: pulp.pulp.LpVariable Therefore, just using print(x) ...


9

You can solve your model via the NEOS server which provides Gurobi, Cplex, and other solvers for free if it is the matter of not having a solver. I am not familiar with PuLP but I know it is easy to implement the solvers in NEOS if you model the problem in Pyomo. May it helps you to find PuLP syntax for it, I provide lines of code written for Pyomo using ...


9

If the model in PuLP is: from pulp import LpProblem, LpVariable, LpMaximize, lpSum m = LpProblem(name='example', sense = LpMaximize) x = LpVariable.dicts(name='x',indexs=[1,2,3]) m += lpSum(x) <= 3, 'c1' m += lpSum(i*x[i] for i in [1,2,3]), 'obj' We can access the coefficient of $x_1$ in 'C1' with: m.constraints['c1'][x[1]] # This the coefficient => ...


7

According to PuLP's documentation, it seems that load_file function in PuLP's Amply class can only handle AMPL files with a subset of AMPL syntax for data. So if you want to use those LP/MPS files in PuLP, you may have to first convert them into AMPL files. You can either write a small script by yourself or use some existing scripts. Here are some ...


5

The rule "works on Saturday implies works on Sunday" can be expressed as $$(D_{i,6} \lor N_{i,6}) \implies (D_{i,7} \lor N_{i,7}),$$ which can be rewritten in conjunctive normal form as follows: \begin{equation} \neg (D_{i,6} \lor N_{i,6}) \lor (D_{i,7} \lor N_{i,7}) \\ (\neg D_{i,6} \land \neg N_{i,6}) \lor (D_{i,7} \lor N_{i,7}) \\ (\neg D_{i,6} \lor D_{i,...


4

There are certainly different ways of achieving what you want. Here is how I would proceed: Start by predefining the set of all possible schedules which satisfy your constraints $2,3,4,6$. Although there are many, I believe that with your constraints, it may be not too difficult to derive them somewhat automatically. Here is a subset of them in the table ...


4

Your code is correct, you have used pulp.LpVariable.dicts correctly. For better readability, it is often better to use dictionaries. So the idea is to convert your data from lists to dicts as follows: # convert data into dicts dict_bike_profit = dict(zip(bike_types, bike_profit)) # simple dict dict_bike_stock = dict(zip(part_names, parts_stock)) # simple ...


4

You don't want to create a variable representing a date in pulp. You want to utilize zero-one indicator variables for each option. In this case your options are the vessel-date combinations. Index the variables by vessel and date. Suppose the value of the difference between the actually loaded date and the ready to be loaded date is to be used in the ...


4

In other words, you want to avoid a pattern of 010. As a logical proposition: $$\neg (\neg V_{i,j} \land V_{i,j+1} \land \neg V_{i,j+2}),$$ which you can write in conjunctive normal form as: $$V_{i,j} \lor \neg V_{i,j+1} \lor V_{i,j+2}.$$ The corresponding linear constraint is: $$V_{i,j} + (1 - V_{i,j+1}) + V_{i,j+2} \ge 1,$$ equivalently, $$V_{i,j} - V_{i,...


3

It is difficult to tell from this information. You need the examine the logs of the solver if your primal bound (how good are the solutions) or dual bound (how good is the relaxation) is not moving as fast as you wish it would be. I would try to run this heuristic not at every node, but maybe at every 50 (the correct value of this needs to be benchmarked) ...


3

I have some experience in solving large-scale airline crew pairing combinatorial optimization problems (an NP-hard problem) with difficulty similar to vehicle routing problems. Yes, solving such problems using standard open-source IP solvers is extremely time-consuming. You could customize/parallelize heuristics (such as Simulated Annealing, Variable ...


3

CBC does have its fair share of bugs, especially when it comes to proper termination. If you are running in multithreaded mode try running in serial (or vice-versa), and see if that helps. If you are feeling particularly adventurous, you can comment out all the code related to the "SIGNAL_TRAP" and recompile CBC. This helps with proper termination (...


3

The following constraints are infeasible : _C129: Rail_Loadings_From_Washplant_('2020_05_22',_'ABC',_'PRE') + Rail_Loadings_From_Washplant_('2020_05_22',_'ABC',_'ZBF') = 25200 _C134: Rail_Loadings_From_Washplant_('2020_05_23',_'ABC',_'PRE') + Rail_Loadings_From_Washplant_('2020_05_23',_'ABC',_'ZBF') = 25200 _C161: ...


3

The latest issue has to do with not having an inventory control constraint. You need to have a constraint like: port_inventory_vars[(date, grade)] == port_inventory_vars[(date-1, grade)] - pulp.LpSum(vessel_sales_demand_vars[(vessel, grade, date)] for vessel in vessels) + ... The ellipsis indicates where you can put additional terms that describe how ...


2

When dealing with infeasibility, I like to do two things: a) Create the Irreducible Infeasible Subset (IIS). I don't think PuLP directly allows you to create that, however you could export your model instance and then use a (commercial) solver (e.g. Gurobi) to do so (see here for docs). This will allow you to narrow down where the infeasibility lies. b) Add ...


2

I have created a model that I believe addresses your objective of minimizing demurrage charges. It utilizes indicator variables for each day and vessel showing when each vessel is finally loaded. The factors for the variables in the objective function are to be calculated based on the demurrage formula you provided. The first thing to do with this model is ...


2

In Pyomo you can use the .fix() method to do that. In the following example based on a condition you can fix some variables to different values: if pyo.value(instance.x[2]) == 0: instance.x[2].fix(1) else: instance.x[2].fix(0) In PuLP: Assigning values to variables also permit fixing those variables to that value. In order to do that, you can use the ...


2

When I understand your question correctly you are not interested in the full solution space. In that case you can generate alternative optimal solutions by first solving your problem to optimality. Then you can add the objective function with the optimal value as a constraint and resolve with a random objective vector. For example for the problem. $ \begin{...


2

Your problem does not have any objective function, so you do not have to use software to solve linear programs here. It is just a system of linear inequalities. (Of course, you still can use LP tools by just minimizing a constant objective function.) May I suggest a solution that neither requires Pyomo nor Pulp? You can solve those systems by using the ...


1

I suggest introducing $3n$ variables. Let $ c_{i} $ be the daily rate of each vehicle $i=1,2,3$. $ x_{i,j} $ designates the quantity of vehicles which will be used every day: the subscript $j$ indicates the day in interest. Supposing to consider $n$ days, we have $j=1, 2, \ldots, n$ days. Clearly, $ x_{i,j} $ is a non-negative integer numbe and $ x_{i,j}=0$ ...


1

I'll address your main issue about discrete dispatch. You should model the problem utilizing inventory levels at discrete time intervals that are short enough to fit just one shipment, which sounds like hourly. Utilize tank volume at the end of time interval $t$: $v_t$ for all $t$ between 1 and the end of the planning horizon. This allows you to create a ...


1

I found the solution. 1- The storage inventory definition is as follows: model += storage_stockpile_current[product] \ + pulp.lpSum( train_consignment_variables[(date, plant, product)] for plant in _plants_combo) \ - sales_demand[date][product] \ == storage_inventory_vars[(...


1

I don't see any part that "storage_facility_vars" is added to your model in your code. You use it only after define as: storage_facility_vars[(date, product)] = plant_current_inv[product] Please check it. Also "plant_current_inv[product]" is used only above row, never defined or initialized.


Only top voted, non community-wiki answers of a minimum length are eligible