mathematical-optimization

Finding the local maxima/peaks and minima/valleys of histograms

不打扰是莪最后的温柔 提交于 2019-11-29 01:02:34
问题 Ok, so I have a histogram (represented by an array of ints), and I'm looking for the best way to find local maxima and minima. Each histogram should have 3 peaks, one of them (the first one) probably much higher than the others. I want to do several things: Find the first "valley" following the first peak (in order to get rid of the first peak altogether in the picture) Find the optimum "valley" value in between the remaining two peaks to separate the picture I already know how to do step 2

Finding all divisors of a number optimization

主宰稳场 提交于 2019-11-29 00:41:46
I have written the following function which finds all divisors of a given natural number and returns them as a list: def FindAllDivisors(x): divList = [] y = 1 while y <= math.sqrt(x): if x % y == 0: divList.append(y) divList.append(int(x / y)) y += 1 return divList It works really well with the exception that it's really slow when the input is say an 18-digit number. Do you have any suggestions for how I can speed it up? Update : I have the following method to check for primality based on Fermat's Little Theorem: def CheckIfProbablyPrime(x): return (2 << x - 2) % x == 1 This method is really

Fast max-flow min-cut library for Python

邮差的信 提交于 2019-11-29 00:24:58
问题 Is there a reliable and well-documented Python library with a fast implementation of an algorithm that finds maximum flows and minimum cuts in directed graphs? pygraph.algorithms.minmax.maximum_flow from python-graph solves the problem but it is painfully slow: finding max-flows and min-cuts in a directed graph with something like 4000 nodes and 11000 edges takes > 1 minute. I am looking for something that is at least an order of magnitude faster. Bounty : I'm offering a bounty on this

How to convert quadratic to linear program?

陌路散爱 提交于 2019-11-28 23:44:31
I have an optimization problem that has in the objective function 2 multiplied variables, making the model quadratic. I am currently using zimpl, to parse the model, and glpk to solve it. As they don't support quadratic programming, I would need to convert this to an MILP. . The first variable is real, in range [0, 1], the second one is real, from range 0 to inf. This one could without a problem be integer. The critical part in the objective function looks like this: max ... + var1 * var2 + ... I had similar problems in the constraints, but they were easily solvable. How could I solve this

Given a target sum and a set of integers, find the closest subset of numbers that add to that target

自闭症网瘾萝莉.ら 提交于 2019-11-28 19:35:00
I have a set of integers M and a target sum k. I want to find the subset of M that when added together is the closest to k without going over. For example: M = {1, 3, 5, 5, 14} k = 12 answer = {1, 5, 5} because 1 + 5 + 5 = 11 and there is no way to make 12. I have the additional constraint that the subset can contain at most 4 elements. In my application, the size of |M| can be large (on the order of thousands of elements). If it is not possible to find the optimal answer in a reasonable time, I am interested in solutions that at least give a "good" answer. Right now I am solving this problem

How to replicate excel solver in R

瘦欲@ 提交于 2019-11-28 17:14:30
问题 I used excel solver to solve an optimization problem, and I am trying to replicate it in R. I found many packages like optim, ROI etc., but it seems all of them only take a vector as the object to optimize and allow the variables to take any continuous value. In my case, I have a constraint matrix that also needs to be satisfied and my variables can only take binary values. Here is problem I want to solve: A-D are machines, 1-3 are tasks and the number in the first matrix is the value

Quadratic Program (QP) Solver that only depends on NumPy/SciPy?

旧城冷巷雨未停 提交于 2019-11-28 16:42:44
I would like students to solve a quadratic program in an assignment without them having to install extra software like cvxopt etc. Is there a python implementation available that only depends on NumPy/SciPy? I ran across a good solution and wanted to get it out there. There is a python implementation of LOQO in the ELEFANT machine learning toolkit out of NICTA ( http://elefant.forge.nicta.com.au as of this posting). Have a look at optimization.intpointsolver. This was coded by Alex Smola, and I've used a C-version of the same code with great success. I'm not very familiar with quadratic

Gurobi objective with python dictionary values

被刻印的时光 ゝ 提交于 2019-11-28 10:22:00
问题 I am using Gurobi 6.0 with Python 2.7. I am curious to know if Gurobi allows the objective function to have values coming from a dictionary with indices of the decision variables. Attaching the code: from gurobipy import * d = { (0, 0): 0, (0, 1): -5, (1, 0): 4, (1, 1): 2, (2, 0): 0, (0, 2): 10 } m = Model() x = m.addVar(vtype=GRB.INTEGER) y = m.addVar(vtype=GRB.INTEGER) m.update() m.addConstr(x + y <= 2) m.setObjective(d[(x, y)], GRB.MAXIMIZE) m.optimize() print m.objVal print x.x print y.x

Maximise sum of “non-overlapping” numbers from matrix

 ̄綄美尐妖づ 提交于 2019-11-28 10:20:32
Just looking for a bit of direction, I realise that the example given is possible to solve using brute force iteration, but I am looking for a more elegant (ie. mathematical?) solution which could potentially solve significantly larger examples (say 20x20 or 30x30). It is entirely possible that this cannot be done, and I have had very little success in coming up with an approach which does not rely on brute force... I have a matrix (call it A) which is nxn. I wish to select a subset (call it B) of points from matrix A. The subset will consist of n elements, where one and only one element is

Free Optimization Library in C# [closed]

核能气质少年 提交于 2019-11-28 06:02:49
Is there any optimization library in C#? I have to optimize a complicated equation in excel, for this equation there are a few coefficients. And I have to optimize them according to a fitness function that I define. So I wonder whether there is such a library that does what I need? ShuggyCoUk Here are a few free and open source c# implementrions Nelder Mead Simplex implementation [ Alternate Link ] Numerical provides a variety of algorithms including: Chromosome Manager Genetic Optimizer Hill Climbing Optimizer Maximizing Point Maximizing PointFactoy Maximizing Vector Minimizing Point