mathematical-optimization

Minimize sum of distances in point pairs

自闭症网瘾萝莉.ら 提交于 2019-12-04 04:18:33
I have a bunch of points on a 2-dimensional Grid. I want to group the Points into pairs, while minimizing the sum of the euclidean distances between the points of the pairs. Example: Given the points: p1: (1,1) p2: (5,5) p3: (1,3) p4: (6,6) Best solution: pair1 = (p1,p3), distance = 2 pair2 = (p2,p4), distance = 1 Minimized total distance: 1+2 = 3 I suspect this problem might be solvable with a variant of the Hungarian Algorithm ?! What is the fastest way to solve the problem? (Little Remark: I always should have less than 12 points.) ChuckCottrill The problem you are trying to solve is

Matrix completion in Python

烈酒焚心 提交于 2019-12-04 03:31:05
Say I have a matrix: > import numpy as nap > a = np.random.random((5,5)) array([[ 0.28164485, 0.76200749, 0.59324211, 0.15201506, 0.74084168], [ 0.83572213, 0.63735993, 0.28039542, 0.19191284, 0.48419414], [ 0.99967476, 0.8029097 , 0.53140614, 0.24026153, 0.94805153], [ 0.92478 , 0.43488547, 0.76320656, 0.39969956, 0.46490674], [ 0.83315135, 0.94781119, 0.80455425, 0.46291229, 0.70498372]]) And that I punch some holes in it with np.NaN , e.g.: > a[(1,4,0,3),(2,4,2,0)] = np.NaN; array([[ 0.80327707, 0.87722234, nan, 0.94463778, 0.78089194], [ 0.90584284, 0.18348667, nan, 0.82401826, 0.42947815]

k-shortest (alternative) path algorithm, java implementations

╄→гoц情女王★ 提交于 2019-12-04 02:39:37
Could you recommend any java library which implements k-shortest algorithm -> searching for alternative ways, not the only shortest one in directed multigraph ? I found only JGraphT but there is actually bug (which i submitted) but it will take a lot of time to fix it i guess, are there any other available implementations ? Except JGraphT i found only small one-man projects :/ OR would be hard to modify Disjktra shortest path alg to show alternative paths ? Thanks Ram Narasimhan 2 Possible Options: Option 1. The class KshortestPath from the MascOpt Package is a good option for a Java

Why does adding Crossover to my Genetic Algorithm gives me worse results?

泪湿孤枕 提交于 2019-12-04 02:12:46
I have implemented a Genetic Algorithm to solve the Traveling Salesman Problem (TSP). When I use only mutation, I find better solutions than when I add in crossover. I know that normal crossover methods do not work for TSP, so I implemented both the Ordered Crossover and the PMX Crossover methods, and both suffer from bad results. Here are the other parameters I'm using: Mutation : Single Swap Mutation or Inverted Subsequence Mutation ( as described by Tiendil here ) with mutation rates tested between 1% and 25%. Selection : Roulette Wheel Selection Fitness function : 1 / distance of tour

Linear Algebra Library For Android [closed]

孤人 提交于 2019-12-04 02:05:29
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Does anyone know what will be a good library for computing linear algebra in Android (SVD, QR, LU, least-squares, inverse, etc) ? The conventional Linear Algebra libraries are implemented in layers. Basic Linear Algebra Subprogram (BLAS) is in the bottom layer. Linear Algebra Package (LAPACK) is built on top of BLAS. The interfaces for these two layer libraries are standardized back in 1990s, and the

Optimization in R with arbitrary constraints

孤街醉人 提交于 2019-12-03 22:47:39
I have done it in Excel but need to run a proper simulation in R. I need to minimize function F(x) ( x is a vector) while having constraints that sum(x)=1 , all values in x are [0,1] and another function G(x) > G_0 . I have tried it with optim and constrOptim . None of them give you this option. The problem you are referring to is (presumably) a non-linear optimization with non-linear constraints. This is one of the most general optimization problems. The package I have used for these purposes is called nloptr : see here . From my experience, it is both versatile and fast. You can specify both

Optimisation/knapsack algorithm with multiple contraints in JavaScript

拟墨画扇 提交于 2019-12-03 21:53:45
I'm looking for a solution to the knapsack problem where multiple constraints are in place. Say our knapsack has a maximum weight of 30kg and we have a set of 100 objects, each with a weight and each with a benefit. These objects could look like this: { name: 'water bottle', weight: 2, benefit: 5 }, { name: 'potatoes', weight: 10, benefit: 6 } Finding the combination of objects with the highest benefit within the maximum weight is simple enough. Here is a nodeJS plugin showing how it can be done... https://gist.github.com/danwoods/7496329 Where I'm struggling is when the objects have more

Wrong result for best fit plane to set of points with scipy.linalg.lstsq?

我们两清 提交于 2019-12-03 20:41:45
I have a set of (x, y, z) points for which I need to find the plane that best fits them. A plane is defined by its coefficients as: a*x + b*y + c*z + d = 0 or equivalently: A*X +B*y + C = z The second equation is just a re-write of the first. I'm using the method developed in this gist , which is a translation to Python from the Matlab code given in this answer . The method finds the coefficients to define the plane equation that best fits the set of points. The issue is that I am able to come up with a set of coefficients that gives a better fit to that set of points . To define "better", I

“Anagram solver” based on statistics rather than a dictionary/table?

不打扰是莪最后的温柔 提交于 2019-12-03 19:11:19
问题 My problem is conceptually similar to solving anagrams, except I can't just use a dictionary lookup. I am trying to find plausible words rather than real words. I have created an N-gram model (for now, N=2) based on the letters in a bunch of text. Now, given a random sequence of letters, I would like to permute them into the most likely sequence according to the transition probabilities. I thought I would need the Viterbi algorithm when I started this, but as I look deeper, the Viterbi

Merging and splitting overlapping rectangles to produce non-overlapping ones

我只是一个虾纸丫 提交于 2019-12-03 17:20:37
I am looking for an algorithm as follows: Given a set of possibly overlapping rectangles (All of which are "not rotated", can be uniformly represented as (left,top,right,bottom) tuplets, etc...), it returns a minimal set of (non-rotated) non-overlapping rectangles, that occupy the same area. It seems simple enough at first glance, but prooves to be tricky (at least to be done efficiently). Are there some known methods for this/ideas/pointers? Methods for not necessarily minimal, but heuristicly small, sets, are interesting as well, so are methods that produce any valid output set at all.