Tag Info

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: type(x) Out: 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] # This the coefficient => ...

8

Suppose your two arrays are indexed by $I$ and $J$, and let $x_i$ be the binary variable. zero or one elements may be selected from first array: $$\sum_{i\in I} x_i \le 1 \tag1$$ zero, one, or many elements may be selected from second array: no constraint needed here if no element is selected from first array, then no element should be selected from ...

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 ...

6

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,... 5 Some comments on your model: you can remove constraints \#1 and \#2, as you have already defined the variables as non negative the problem is infeasible, because the inventory is not a variable, it is already defined and is an input of the model. Consequently, with constraints \#4, ROQ variables are also defined and have no other possible values than ... 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 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 I think pySCIPOpt might be a good choice, provided you are willing to make minor changes to the code. The modelling interface is very similar to Gurobi and the underlying SCIP solver also supports handy modelling features like indicator constraints or logical AND/OR/XOR constraints. Alternatively, you could save all your models as MPS files and solve them ... 4 The model you linked in the question will do the job. You just set a_{jt}=0 if a worker on shift j would be taking a break at time t. 4 Introduce linear constraints:$$\sum_{\text{h}} z[\text{h}][\text{driver}] \le 1 \quad\text{for each driver}$$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 ... 3 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{... 3 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 ... 3 I believe the issue was with the following constraint name: # If Koramangala 5th Block, then one must be Italian model += (y['koramangala_5th_block_bin'] <= x['italian_bin'], '5th_block_italian') It seems that PuLP did not like the name starting with a number even though it was a string. If I changed the constraint to this, the model ran. # If ... 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 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 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 ... 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 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 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) == 0: instance.x.fix(1) else: instance.x.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 Math Formulation + Pyomo model We need to define 3 sets i: 1 to 8 staffs j: 1 to 3 shifts t: 1 to 18 days X_{i,j,t} \in {0/1}  Binary There must be 3 people on each shift \forall t,j  then \sum_i X_{i,j,t} =3 Every individual (i) must work 1 shift per day\ \forall t,i  then \sum_j X_{i,j,t} \geq 1  Every individual must not work more than 2 ... 1 I am not sure of the bounds of the problem, but I'll try to provide an answer. Let's consider the following two sets:$$ V = \{v: vehicles\} \\ T = \{t: days\} $$Now, we have the parameters you have provided, which I understand are the following:$$ VCAP_v: \text{capacity of vehicle v} \\ VCOST_v: \text{cost of vehicle v}\\ D_t: \text{demand of day t}  ...

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[(...

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