Hot answers tagged

49

Regardless of what completes the phrase "Python vs ...", the answer is always going to be Python. Very few people who are serious about using optimisation in production use MATLAB, and the ones who do can't wait to move away from it. As to why, there are plenty of reasons. MATLAB is: licensed closed source not object-oriented friendly, so it's a very bad ...


18

I agree with everything Nikos said and I add some colors to some of the reasons: Python is free and open-source but Matlab is not. Anyone can write codes in Python and share it with others who can easily run that code (as it's free software) but your Matlab codes can be run only by those who have a license. Just because Python is open-source and free, it ...


16

Nikos Kazazakis and EhsanK have given you great reasons for using Python. I will focus on the point from you about needing to use an additional package/library in Python for matrix and vector operations. In industry projects you will encounter many challenges and things you want to do, but you don't want to (and shouldn't) implement. Currently I work on a ...


14

I work for a company that offers a commercial optimization solver. The solver offers interfaces to both MATLAB and Python for solving problems defined in those languages. We only get one or two queries about MATLAB interfacing with our product per year, but we get many times that amount of questions on interfacing Python with our product. Many bluechip and ...


14

Numerical stability (computations going sideways) and numerical tolerances are related but not identical. Floating point arithmetic being subject to rounding and truncation errors (unavoidably), every solver will need to treat things that are "nearly nonnegative", "nearly zero" or "nearly integer" as if they are in fact nonnegative / zero / integer. That ...


10

The problem might be @(x) in the first line of the function. Adding this creates an anonymous function, while MATLAB simply expects a numerical vector as output. Removing @(x) should resolve the issue. Using ceq = [] should not give any problems.


9

MATLAB is a language built on top of a library. Python (with NumPy & numba) is a language with a library built under it. Neither is ideal. Like all languages, both have a few quirks, due to their history. My suggestion: Door Number 3, Julia. In either case (MATLAB, Python, Julia), you should ask yourself: Is your immediate goal to master the math, or to ...


8

I assume the solver you're referring to in Python/R/Matlab, are the open-source solvers such as CBC or GLPK (you can find out more in this question: Where can I find open source LP solvers?). If that's the case then you should consider: The size of the problem Solution time: which can be very different between open-source and commercial solvers How much ...


8

Following Kevin Dalmeijer's answer (Accepted), I found the following approach to solve the problem that I had. (composing this answer for future similar questions): The general form of Fmincon function (minimizing constrained nonlinear multivariable function) in Matlab optimization toolbox is as follow: Option 1: fmincon(ObjFun,x0,A,b,Aeq,beq,lb,ub,@nonlcon,...


8

I did my PhD on a topic involving numerical simulations of mechanical systems. I worked primarily in MATLAB, which I already had experience in and seemed to have some good 'out of the box' optimisation algorithms. Looking back, I wish I did my work in Python. I work in Software Engineering now and Python is a lot more applicable to other languages and looks ...


7

Mention of intlinprog, without further specification, generally means the intlinprog of the MATLAB Optimization Toolbox. However, Gurobi also has a function called intlinprog, which mimics the interface of the MATLAB Optimization Toolbox intlinprog, but which calls the Gurobi solver. Similarly with Mosek. CPLEX has cplexintlinprog, which mimics the ...


7

Since you are asking from a MSc student's point of view and actually need to use CPLEX, I assume that your research mainly focuses on the applications of OR. Therefore, two things are required to be considered. How difficult it is to implement your model? What is the possible solving approach for this model? My suggestion: If your research problem can ...


6

(1) Numerical stability is a real issue but not so common in my area of discrete optimisation (for obvious reasons). I only get it in two cases. Sometimes I get preprocessed data that has been rounded, resulting in nearly parallel constraints. Other times I badly implement an iterative algorithm like Benders decomposition, which produces more numerical error ...


6

I am geophysics professor and have been solving scientific computing problems in Matlab since 2000. In the last ~8 years graduate students have been preferring to work in Python. I have the following observations: On a practical level Python is MUCH slower than Matlab. Code that my graduate students write is literally orders of magnitude slower than my ...


6

In Python, with pulp and networkx : import pulp import networkx as nx G = nx.Graph() # define your graph here #... # define the problem prob = pulp.LpProblem("MinimumSetVertexCover", pulp.LpMinimize) # define the variables x = pulp.LpVariable.dicts("x", G.nodes(), cat=pulp.LpBinary) z = pulp.LpVariable.dicts("z", G.edges(), ...


5

Use CVX's entr function. $\sum_{i=1}^ 4x_i\ln(x_i)$ can be entered as -sum(entr(x)) entr Scalar entropy. entr(X) returns an array of the same size as X with the unnormalized entropy function applied to each element: { -X.*LOG(X) if X > 0, entr(X) = { 0 if X == 0, { -Inf otherwise. If X ...


5

If you want to work inside Excel (or LibreOffice), you might look at OpenSolver. Google's OR-Tools includes the CBC solver and the option to use GLPK, SCIP or Gurobi. (Gurobi is commercial software with a free academic license.)


5

Depending on the type of your MIP, there are numerous open-source options: MILP: CBC Convex MINLP: Bonmin Non-convex MINLP: Couenne All of the above: SCIP (free for academics)


5

There are several open-source software packages that use branch-and-bound to solve integer programming, for example: GLPK: https://www.gnu.org/software/glpk CBC: https://github.com/coin-or/Cbc


4

The main reasons are performance and quality of numerics. Non-professional stuff tend to lack the polish professionals spend time doing to ensure that numerical issues don't compromise the solving procedure. Performance-wise, a good rule of thumb is problem density: if a problem is large but really sparse, open source solvers can perform really well. If a ...


4

You can specify many nonlinear constraints and objectives without having to define functions with the problem-based modeling approach starting with MATLAB R2019a. "Many" are those that are polynomial or rational expressions. For example: p = optimproblem; x = optimvar("x","LowerBound",0); y = optimvar("y","LowerBound",0); p.Objective = x + y; p....


4

My first language I have learned was MATLAB. After learning C++ I realized MATLAB is bad for really learning about programming in such. I would recommend you also Python as language because it is easier to switch from Python to MATLAB then in the other direction. Besides the downturns of commercial and closed software you should also keep in mind that ...


4

Sounds like you are intending to build solvers. You will be better off in MATLAB. As you noted, matrix and vector operations are part of the language. You'll need matrix decompositions and maybe eigenvalue solvers to build your solvers, probably for dense and sparse matrices, and MATLAB has all of those. If you find that there's a library you need in some ...


3

If you look at the "allowable decrease" in the RHS of the highlighted constraint, it's zero. A number of the binding constraints have either allowable increase or allowable decrease zero. That means that your primal solution is degenerate, and your dual problem has multiple optima. The highlighted difference probably means that the simplex solver ...


3

Here is the model you can write using LocalSolver, our global optimization solver. Please note that LocalSolver is a commercial software like MATLAB. Nevertheless, you can benefit from free trial or academic licenses. function model() { x[i in 1..2][t in 1..5] <- int(0, 5); EDB <- float(-1e3, 1e3); alpha <- float(-1e3, 1e3); for[t in 1..5] ...


2

I am not an expert in YALMIP but you may check the saveampl(F,h,filename) command written in YALMIP website. An example of the implementation is given as: x = sdpvar(3,1); A = randn(5,3); b = randn(5,1); c = randn(3,1); F = [A*x <= b, integer(x(2:3))]; saveampl(F,c'*x,'myamplmodel.mod'); where I think you can save the model with .mps extension instead ...


2

As a veteran MATLAB user, I'm horrified by some of the conventions the developers of Python chose to use. There are some inconsistencies in array notation that are very troubling. They decided to defy convention used in many other programming languages, including MATLAB, C, FORTRAN, Julia, etc. Matrix manipulation is extremely difficult and prone to error in ...


2

I'd go with Python because Python is a general purpose programming language and is much more widely used in industry than MATLAB. In the industry you rarely find yourself just code optimization algorithms or models in your daily work. It is more like you write an entire pipeline from data acquisition, data cleaning, model development (both statistical ...


1

Impossible in cvx since absolute value of a complex expression effectively is something represented using second-order cones/quadratics, and you thus have a nonconvex quadratic constraints since you are bounding that term from below, and that is not supported in cvx. Not possible to represent using reformulations with binary variables either. That would be ...


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


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