mathematical-optimization

gurobi - Error code = 10004 Unable to retrieve attribute 'X'

巧了我就是萌 提交于 2019-12-01 03:03:50
问题 I am getting an error in my c++/gurobi file: Error code = 10004 Unable to retrieve attribute 'X' I read that this might have something to do with labels? But I don't see how there is a problem. It works for some input files, but not for others. So I have created a toy file, t5.txt in attachment. This file does not work, but removing the last column and setting 8 to 7 fixes it. I am puzzled... Below is the output of model.write. Everything seems to make sense, any Ideas what I am doing wrong?

Find first root of a black box function, or any negative value of same function

做~自己de王妃 提交于 2019-12-01 01:40:32
I have a black box function, f(x) and a range of values for x. I need to find the lowest value of x for which f(x) = 0. I know that for the start of the range of x, f(x) > 0, and if I had a value for which f(x) < 0 I could use regula falsi, or similar root finding methods, to try determine f(x)=0. I know f(x) is continuous, and should only have 0,1 or 2 roots for the range in question, but it might have a local minimum. f(x) is somewhat computationally expensive, and I'll have to find this first root a lot. I was thinking some kind of hill climbing with a degree of randomness to avoid any

How to do nonlinear complex root finding in Python

爷,独闯天下 提交于 2019-12-01 01:36:43
问题 I want to do a root search for the following nonlinear equations, I do it in Python but it doesn't work. my code is below from pylab import * import scipy import scipy.optimize def z1(x,y): temp=1+1j+x+2*y; return temp def z2(x,y): temp=-1j-2*x+sqrt(3)*y; return temp def func(x): temp=[z1(x[0],x[1])-1.0/(1-1.0/(z2(x[0],x[1]))),1-2.0/(z2(x[0],x[1])-4.0/z1(x[0],x[1]))] return temp result=scipy.optimize.fsolve(func,[1+1j,1+1j]) print result when I run it, it shows errors: ---> 30 result=scipy

Access all variables occurring in a pyomo constraint

假装没事ソ 提交于 2019-12-01 01:24:32
I am working on an algorithm in python that needs to modify concrete (mixed-integer nonlinear) pyomo models. In particular, I need to know which variables are present in a general algebraic constraint . E.g. for a constraint model.con1 = Constraint(expr=exp(model.x_1) + 2*model.x_2 <= 2) I would like to make a a query (like model.con1.variables ) which returns (a list of) the variables ( [model.x_1,model.x_2] ). In this documentation I find that for linear constraints, the parameter variables exactly serves my purpose. However, the models I'm working with will also contain general algebraic

Implementation of Matlab's fmincon function in C++

爷,独闯天下 提交于 2019-12-01 01:22:39
We're currently using Matlab's fmincon function to do non-linear optimization for a project I'm working on. We need to port that part of the project to C++ in order to integrate it with other parts of the project. Is there a good way to compile the fmincon function into a library that we can use in C++? Or, is there already a library available somewhere that implements fmincon ? If neither of the above are an option, what optimization libraries are available that would be fairly easy to switch to from fmincon ? Background info: We're trying to optimize a waypoint flight path of a UAV to follow

Solving system of nonlinear equations with python

妖精的绣舞 提交于 2019-12-01 01:10:36
问题 Can I solve a system of nonlinear equations in terms of parameters in python? Is there a example or tutorial? I can do this easily in maple, but the expressions for my particular system are pretty big and copying them over is quite hard. Example: sigma*(y-x) = 0 x*(rho-z)-y = 0 x*y-beta*z = 0 You should get the solutions: [[x = 0, y = 0, z = 0], [x = sqrt(beta*rho-beta), y = sqrt(beta*rho-beta), z = rho-1], [x = -sqrt(beta*rho-beta), y = -sqrt(beta*rho-beta), z = rho-1]] The reason I ask: I

Using scipy to minimize a function that also takes non variational parameters

陌路散爱 提交于 2019-12-01 00:18:21
I want to use the scipy.optimize module to minimize a function. Let's say my function is f(x,a) : def f(x,a): return a*x**2 For a fixed a , I want to minimize f(x,a) with respect to x . With scipy I can import for example the fmin function (I have an old scipy: v.0.9.0), give an initial value x0 and then optimize ( documentation ): from scipy.optimize import fmin x0 = [1] xopt = fmin(f, x0, xtol=1e-8) which fails because f takes two arguments and fmin is passing only one (actually, I haven't even defined a yet). If I do: from scipy.optimize import fmin x0 = [1] a = 1 xopt = fmin(f(x,a), x0,

Pareto optimization - non-dominated points

家住魔仙堡 提交于 2019-11-30 23:18:37
I wrote an algorithm that returns a list similar to that which nsga2 returns. (nsga2 of package "mco" ( pdf )) The algorithm can not itself recognize if a point is non-dominated. Some of the points it returns are dominated and it only contains the points and their values, not the logic-vector that nsga2 returns. I am trying to get the non-dominated points (not their values). With nsga2's result you can use paretoSet() to get the values, however that depends on that the logic-vector has been precomputed during nsga2. I also looked at paretoFront()/paretoFilter() of "mco" and nondominated_points

Integer linear programming: example and good tools?

跟風遠走 提交于 2019-11-30 22:42:38
Find a vector x which minimizes c . x subject to the constraint m . x >= b, x integer. Here's a sample input set: c : {1,2,3} m : {{1,0,0}, {0,1,0}, {1,0,1}} b : {1,1,1} With output: x = {1,1,0} What are good tools for solving this sort of problem, and examples of how to use them? Mathematica Mathematica has this built in. (NB: Mathematica is not free software.) LinearProgramming[c, m, b, Automatic, Integers] outputs: {1, 1, 0} GLPK I'm offering an answer using GLPK's glpsol , but I hope there are much better ways to do this (it seems like GLPK is overly powerful/general for this kind of

Create scipy curve fitting definitions for fourier series dynamically

荒凉一梦 提交于 2019-11-30 21:03:39
I'd like to achieve a fourier series development for a x-y-dataset using numpy and scipy . At first I want to fit my data with the first 8 cosines and plot additionally only the first harmonic . So I wrote the following two function defintions: # fourier series defintions tau = 0.045 def fourier8(x, a1, a2, a3, a4, a5, a6, a7, a8): return a1 * np.cos(1 * np.pi / tau * x) + \ a2 * np.cos(2 * np.pi / tau * x) + \ a3 * np.cos(3 * np.pi / tau * x) + \ a4 * np.cos(4 * np.pi / tau * x) + \ a5 * np.cos(5 * np.pi / tau * x) + \ a6 * np.cos(6 * np.pi / tau * x) + \ a7 * np.cos(7 * np.pi / tau * x) + \