Questions tagged [python]

For questions about solving Operations Research problems using the Python programming language.

Filter by
Sorted by
Tagged with
2
votes
1answer
14 views

warmstarting simplex algorithm- how much can problems differ from each other?

I'm working on an implementation of the simplex algorithm. I want to solve problems in real time every 30 minutes. They could be interpreted as a classic transportation problem. I couldn't really say ...
2
votes
0answers
30 views

Is the Dynamic programming in Operations Research book the same dynamic programming in software industry?

Mostly when I search dynamic programming in google I get : dynamic programming (DP) in python, in C++, in java from web pages like geekforgeeks, litecode, codechef, and so on. But in the operation ...
1
vote
1answer
66 views

Efficient solver for multiway number partitioning

I am interested in the following problem. The input is a set of $n$ integers, and a fixed integer $k$. The required output is a partitioning of the integers into $k$ subsets, such that the smallest ...
0
votes
1answer
31 views

Mutable parameter in Pyomo causes a problem

I am defining a Pyomo model that should have some mutable Big-M parameters whose values should be dynamically assigned (once). However, I am having a problem with a difference equation as described in ...
0
votes
0answers
36 views

Error message in difference equation in Pyomo

I have a problem with a difference equation in Pyomo that I just do not understand. Let's say I would like to implement just a very easy difference equation of the form: Temperature(t) = Temperature (...
3
votes
1answer
40 views

Control & Experimental Group Selection Methodology using STDEV and T-Test?

I would like to know if my methodology was 'correct': I am trying to conduct an experiment on my stores. I would like to find out the effect of a marketing campaign on the number of transactions. Only ...
0
votes
0answers
62 views

Use if-statements when defining a constraint in Pyomo

I would like to define the value of a variable model.variable_costsPerTimeSlot [t] in pyomo and I would like to use if-statements. Depending on the value of the if-...
2
votes
2answers
79 views

Trouble with optional nodes in a VRP model using Gurobi for python

I am currently working on a VRP problem where the vehicles are electric. This means that I have range restrictions, and charging stations as nodes which are optional to visit. In my model I have the ...
1
vote
1answer
24 views

How to assure a range for a specific variable in Pyomo

I would like to specify a certain range for a variable for a certain timeslot in Pyomo. I have a temperature variable $T(t)$ that is defined by using the difference equation $$T(t) = T(t-1) + \cdots,\...
1
vote
1answer
112 views

Dynamic Programming - Formulating recurrence relation

We wish to apply dynamic programming techniques to find the optimal betting strategy for a pool to wager on the outcome of the NCAA men's basketball tournament 64 teams compete in a single ...
3
votes
1answer
61 views

Clustering problem involving multidepots and customers requiring commodities located exclusively in an specific depot

I'm trying to solve a clustering problem that's similiar to a VRP Pickup and Delivery problem with multiple depots and customers. Each customer demands a commodity that is exclusively found on one ...
2
votes
1answer
63 views

Impose binary constraint on integer matrix with CVXPY

So I have the following matrix: \begin{equation} P_{i,j}= \begin{bmatrix} x_0 & x_1 & x_2 \\ y_0 & y_1 & y_2 \\ z_0 & z_1 & z_2 \end{bmatrix} \end{equation} where ...
1
vote
0answers
65 views

Strange Result from GurobiPy

I am trying to understand why GurobiPy gives me a strange result for a simple linear programming model coded as below? Why is the optimality gap is 0%? Please let me know if you spot any errors in the ...
3
votes
0answers
81 views

Proving convexity for a function with summation and integer variable

I would like to show that the function $f$ is convex in $\rho\in [0,1)$ under $s\in \mathbb{Z}^+$. When I use Sympy packages of Python to find $\displaystyle\frac{\partial^2 f(\rho)}{d\rho^2}$. I get ...
1
vote
1answer
69 views

Job Shop Scheduling Problem: jobs are scheduled on the same machine at the same time

I want to solve a job shop scheduling problem. I got $n$ Jobs that have to be scheduled on $k$ Machines. A Job $i$ has 2 or 3 Tasks $j$, and there is a known sequence of the Tasks of a Job. One ...
2
votes
0answers
47 views

How to assign a single value to Pyomo parameter without a dictionary

I would like to assign a single value to a paramter that depends on a created set in Pyomo. I have the following code: ...
2
votes
0answers
33 views

Add Variables in Bulk for ortools

I am using the Python ortools to solve large LPs where the number of variables and constraints are in the hundred thousands ($10^5$). Surprisingly, it takes longer ...
2
votes
1answer
86 views

Pyomo can't find Gurobi solver

I have a pyomo model that I can solve using the GLPK solver by just using the code: ...
3
votes
1answer
101 views

Referencing of sets in Pyomo objectives

I have a question about referecing set in Pyomo objectives. Basically I have 2 options and I do not understand why one of it works whereas the other yields an error. Here you see them: ...
1
vote
1answer
54 views

How to display results from a solver during solving in Pyomo

I would like to see the current results (e.g. MIP gaps) of a solver in pyomo (as in GAMS) while solving the problem. I read that I should use the option "stream-solver" (see for instance ...
1
vote
1answer
93 views

Solving general minimum cost flow problems using only one demand and one supply node

This is a practice in using reduction. Suppose I have a solver that only allows input to a MCF that specifies only one demand and one supply node. How could I use this solver to solve general MCF ...
2
votes
1answer
48 views

How to implement a difference equation in Pyomo

I would like to define a difference equation in pyomo for a temperature variable. The equation (simplified) looks like: $Temperature(t) = Temperature (t-1) + x(t)$ , for t>0 $Temperature (0) = 20 $ ...
1
vote
1answer
39 views

Python Gurobipy Maximum Flow: How to model “source” and “sink” in constraints

I am attempting to capture the nature of a "source" node as well as a "sink" node where the net flow for each node aside from the source and sink is zero. Here is my code so far: <...
3
votes
0answers
32 views

PuLP Python: How to linearize an inequality involving an integer variable

I am working on a Copper payables problem where the objective function is to maximise the sum of copper payable over a time period, T. The total amount of payable tonnes i.e. what the customer will ...
2
votes
1answer
59 views

Generating a different optimal solution from CPLEX for each run

I recently chanced upon the idea of solution diversity through the setting of random seeds within CPLEX. However, the documentation page on the settings does not shed any light with regard to the ...
1
vote
1answer
142 views

Pyomo can't find solver

I am new to Pyomo and I have the following optimization problem (original transport problem by Dantzig): ...
2
votes
1answer
66 views

How to define constraints in Pyomo using sets and variables

I am trying to model the transportation problem of Dantzig in Pyomo (see the GAMS code here https://www.gams.com/latest/gamslib_ml/libhtml/gamslib_trnsport.html or the description here https://www....
3
votes
1answer
97 views

Why functions with arguments can be called without arguments in Pyomo

I have a question regarding pyomo. I have seen quite often, that for the definition of parameters, objectives and constraints, explicit functions are defined. These functions expect some arguments and ...
2
votes
1answer
87 views

Recommended python solver for an online optimization problem

I need to implement a load scheduling algorithm that involves solving an online optimisation problem from a research paper for my Real time systems course. This convex optimisation problem is setup ...
2
votes
1answer
65 views

Fixing the amount of variable in Gurobi - Python as a parameter for another model

I have solved a very simple mathematical model ( 2 variables) using Gurobi in Python and now I want to fix the amount of the variable in another model and solve it, for example, consider the variable $...
2
votes
1answer
86 views

Converting evolutionary optimization problem from Excel to Python

I've set up and successfully executed an evolutionary optimization in Excel, and now have a need to convert the problem to Python. differential_evolution() in the ...
4
votes
1answer
69 views

How to convert static variables into arrays for use with PuLP

I have the following code in Python and PuLP which uses static variables. I want to know how to solve the problem by converting all of the LpVariable parts into an array, as well as the constraints. ...
4
votes
1answer
75 views

Binary variables with multiple indices

I'm new to Cplex and I'm working with the python API. I have a variable $w^t_{iksm}$ and I could just find the binary_var_cube function which only accepts 3 indices. I'm then using this $w$ to define $...
2
votes
1answer
148 views

Error when defining variables in Pyomo

I just started to learn about Pyomo. In several tutorials it is stated that the command for creating a variable is just model.Variable = VAR(...). However, I get ...
2
votes
1answer
79 views

Formulating “more complicated” objectives in Python Gurobi

I am currently learning how to use Gurobi for Python using their official tutorial found here. In this example, they appear to formulate the objective by simply specifying a cost dictionary to the <...
1
vote
0answers
114 views

Doesn't Pyscipopt handle nonlinear objective functions?

I am trying to solve a large-scale nonlinear problem. Below is the objective function coded for pyscipopt. I have some loops over a list of tuples (r,p,s) in the list RouteTimeStop, and the only ...
5
votes
2answers
89 views

Solve nonlinear programming problems practically

In an exam, I studied Theoretical approaches to converting constrained minimum problems into unconstrained minimum problems. Specifically: KKT conditions Projection Gradient Descent Penalty and ...
4
votes
1answer
51 views

Greedy algorithms for assignment problems — prediction doesn't match simulation

I'm considering the following basic assignment problem: a group of $n$ people is to be assigned, in one-to-one fashion, a set of $n$ jobs. Write $C_{ij}$ for the cost incurred when person $i$ gets ...
0
votes
2answers
198 views

How to generate multiple solutions to linear program in Python?

I recently posted a question here where I had written some Pyomo code to solve a simple linear program, however I feel the Operations Research platform is perhaps a better fit for this question. My ...
5
votes
1answer
365 views

Python for OR: Which non-solver libraries do you use?

If you're programming OR challenges in Python, besides using mathematical optimization software (= constraint solvers), which other libraries do you often use? Maybe for mundane tasks such as data ...
1
vote
1answer
76 views

How can I formulate an objective function that minimises the number of items required to solve a problem

I am currently trying to solve a problem where I need to minimise transport cost through the choice of vehicle (and how many of each choice) subject to a given demand. The problem: There are currently ...
2
votes
1answer
81 views

Ordering Nodes of a graph according to their degree

In an undirected graph, I would like to order its nodes according to their degree. However, to do this I have to enter the edges of the graph first. When I do this, NetworkX in Python reads the nodes ...
2
votes
2answers
286 views

Cutting Stock Problem : Mixed Integer Programming

I am asked to solve the following problem: The problem: You were asked to repair a farm house with sheets of plywood. You were given thirty sheets of plywood. (each size = 10ft x 10ft) The house ...
3
votes
2answers
141 views

Google OR returning different values depending on language

Lately, I have been working on a CP-SAT model for solving multi-resource flexible job shop problems. I used the code (1) as an inspiration for building code (2) in Python which works well. Then I had ...
1
vote
0answers
44 views

How can I see the engine log when solving a LP using pulp (python)?

I wonder which command should I use to see how the steps the pulp solver is doing when solving a linear program.
1
vote
1answer
120 views

Python, Google OR-Tools, OnlyEnforceIf() method

I am trying to solve a basic puzzle by using Google OR-Tools, this is my first try with OR-Tools and I am trying to learn. I completed almost everything and was ready to conclude the program until I ...
1
vote
0answers
56 views

Modeling the multiplication of two binary decision variables in undirected graph in python

In an undirected graph, I'm trying to model a constraint that forcing the optimizer to set an edge $(u,v)$ between two nodes to only exist (= $1$) if the two nodes have been selected to be $1$. The ...
1
vote
0answers
20 views

Implement geometric constraint using DOCplex

currently I'm working on a wind farm layout optimization problem. I found an appropriate model in literature (Fischetti et al.) and now I'm trying to reproduce it using the Python API of cplex with ...
1
vote
0answers
26 views

MILP formualtion for Two-level minimum dominating set (MDS) problem?

I'm working on an optimization problem which is kind of finding the minimum dominating set (MDS) or the minimum vertex set (MVS) in an undirected graph. given the MILP formulation for both problems, I ...
2
votes
1answer
65 views

Maximum bipartite matching with breakpoints in edge weight function

I am looking for an analogy to the problem I am facing or better yet a paper or even code. I have: Nodes from set A and B. Edges are from a single A to many B. I am framing a max bipartite matching ...