nonlinear-optimization

Rounding LinearExpr with google or-tools SAT solver

好久不见. 提交于 2020-07-21 07:08:53
问题 I'm creating a constraint (in Java) using or-tools SAT solver: IntVar x, y, z; IntVar[] variables = new IntVar{x, y, z}; int[] multiplier = new int{2, 3, 3}; LinearExpr expression = LinearExpr.scalProd(variables, multiplier); //2x + 3y + 3z model.addLessThan(expression, q); Where q is some given integer. The thing is that I need to round the expression result. Something like: if(expression < 25) { expression = 0; } else if(expression < 75) { expression = 50; } else if(expression < 125) {

Rounding LinearExpr with google or-tools SAT solver

南楼画角 提交于 2020-07-21 07:08:12
问题 I'm creating a constraint (in Java) using or-tools SAT solver: IntVar x, y, z; IntVar[] variables = new IntVar{x, y, z}; int[] multiplier = new int{2, 3, 3}; LinearExpr expression = LinearExpr.scalProd(variables, multiplier); //2x + 3y + 3z model.addLessThan(expression, q); Where q is some given integer. The thing is that I need to round the expression result. Something like: if(expression < 25) { expression = 0; } else if(expression < 75) { expression = 50; } else if(expression < 125) {

Rounding Non-LinearExpr with google or-tools SAT solver

与世无争的帅哥 提交于 2020-07-10 10:27:07
问题 Using CP-SAT of google or-tools I'm trying to write this constraint: q >= (50x + 100y + 150z + 200k + 250p + 300v) / (x + y + z + k + p + v) Where q is a simple integer. The thing is I need to round the right side of the equation (let's call it expression ) as follows: if(expression < 75) { expression = 50; } else if(expression < 125) { expression = 100; } else if(expression < 175) { expression = 150; } else if(expression < 225) { expression = 200; } else if(expression < 275) { expression =

How can I emulate Microsoft Excel's Solver functionality (GRG Nonlinear) in C#?

坚强是说给别人听的谎言 提交于 2020-02-26 06:10:12
问题 I have a non-linear optimization problem with constraints. It can be solved in Microsoft Excel with the Solver add-in, but I am having trouble replicating that in C#. My problem is shown in the following spreadsheet. I am solving the classic A x = b problem but with the caveat that all components of x must be non-negative. So instead of using standard linear algebra I use Solver with the non-negative constraint, minimizing the sum of the squared differences, and get a reasonable solution. I

Scipy.optimize terminates successfully for infeasible NLP

假如想象 提交于 2020-01-23 11:26:59
问题 Tried solving an NLP using the scipy.optimize SLSQP. The problem is clearly infeasible but the minimize function in scipy.optimize seems to disagree. minimize X^2 + Y^2 subject to X + Y = 11 X, Y >= 6 The code: from scipy.optimize import minimize def obj(varx): return varx[1]**2 + varx[0]**2 def constr1(varx): constr1 = -varx[0]-varx[1]+11 return constr1 bnds = [(6,float('Inf')),(6,float('Inf'))] ops = ({'maxiter':100000, 'disp':'bool'}) cons = ({'type':'eq', 'fun':constr1}) res = minimize

Scipy.optimize terminates successfully for infeasible NLP

心不动则不痛 提交于 2020-01-23 11:26:12
问题 Tried solving an NLP using the scipy.optimize SLSQP. The problem is clearly infeasible but the minimize function in scipy.optimize seems to disagree. minimize X^2 + Y^2 subject to X + Y = 11 X, Y >= 6 The code: from scipy.optimize import minimize def obj(varx): return varx[1]**2 + varx[0]**2 def constr1(varx): constr1 = -varx[0]-varx[1]+11 return constr1 bnds = [(6,float('Inf')),(6,float('Inf'))] ops = ({'maxiter':100000, 'disp':'bool'}) cons = ({'type':'eq', 'fun':constr1}) res = minimize

Scipy optimize.minimize function

老子叫甜甜 提交于 2020-01-17 15:00:29
问题 I try to solve nonlinear programming task using scipy.optimize.minimize max r x1**2 + y1**2 <= (1-r)**2 (x1-x2)**2 + (y1-y2)**2 >= 4*r**2 0 <= r <= 1 So I've wrote next code: r = np.linspace(0, 1, 100) x1 = np.linspace(0, 1, 100) y1 = np.linspace(0, 1, 100) x2 = np.linspace(0, 1, 100) y2 = np.linspace(0, 1, 100) fun = lambda r: -r cons = ({'type': 'ineq', 'fun': lambda x1, r: [x1[0] ** 2 + x1[1] ** 2 - (1 - r) ** 2], 'args': (r,)}, {'type': 'ineq', 'fun': lambda x2, r: [x2[0] ** 2 + x2[1] **

Scipy optimize.minimize function

与世无争的帅哥 提交于 2020-01-17 15:00:22
问题 I try to solve nonlinear programming task using scipy.optimize.minimize max r x1**2 + y1**2 <= (1-r)**2 (x1-x2)**2 + (y1-y2)**2 >= 4*r**2 0 <= r <= 1 So I've wrote next code: r = np.linspace(0, 1, 100) x1 = np.linspace(0, 1, 100) y1 = np.linspace(0, 1, 100) x2 = np.linspace(0, 1, 100) y2 = np.linspace(0, 1, 100) fun = lambda r: -r cons = ({'type': 'ineq', 'fun': lambda x1, r: [x1[0] ** 2 + x1[1] ** 2 - (1 - r) ** 2], 'args': (r,)}, {'type': 'ineq', 'fun': lambda x2, r: [x2[0] ** 2 + x2[1] **

How to perform Integer Linear Programming in Apache Commons Math

狂风中的少年 提交于 2020-01-17 08:16:12
问题 The org.apache.commons.math3.optim.linear package in Apache Commons Math Library allows Linear Optimization but the returned values are double. Is there any way to perform Integer Linear Programming using this library? I tried googling but there seems to be no mention of ILP anywhere. Alternatively, is there any other Java library that can do ILP? please not that I need to run this on android so SCPSolver, GLPK, Or-tools. etc. are not possible. Thanks in advance. 回答1: As this question and