mathematical-optimization

Using min/max *within* an Integer Linear Program

天涯浪子 提交于 2019-11-27 05:22:18
问题 I'm trying to set up a linear program in which the objective function adds extra weight to the max out of the decision variables multiplied by their respective coefficients. With this in mind, is there a way to use min or max operators within the objective function of a linear program? Example: Minimize (c1 * x1) + (c2 * x2) + (c3 * x3) + (c4 * max(c1*x1, c2*x2, c3*x3)) subject to #some arbitrary integer constraints: x1 >= ... x1 + 2*x2 <= ... x3 >= ... x1 + x3 == ... Note that (c4 * max(c1

How to concatenate two integers in C

早过忘川 提交于 2019-11-27 05:15:42
Stack Overflow has this question answered in many other languages, but not C. So I thought I'd ask, since I have the same issue. How does one concatenate two integers in C? Example: x = 11; y = 11; I would like z as follows: z = 1111; Other examples attempt to do this with strings. What is a way to do this without strings? I'm looking for an efficient way to do this in C because in my particular usage, this is going into a time critical part of code. Thanks in Advance! Mooing Duck unsigned concatenate(unsigned x, unsigned y) { unsigned pow = 10; while(y >= pow) pow *= 10; return x * pow + y; }

How to display progress of scipy.optimize function?

那年仲夏 提交于 2019-11-27 04:11:13
I use scipy.optimize to minimize a function of 12 arguments. I started the optimization a while ago and still waiting for results. Is there a way to force scipy.optimize to display its progress (like how much is already done, what are the current best point)? As mg007 suggested, some of the scipy.optimize routines allow for a callback function (unfortunately leastsq does not permit this at the moment). Below is an example using the "fmin_bfgs" routine where I use a callback function to display the current value of the arguments and the value of the objective function at each iteration. import

Maximise sum of “non-overlapping” numbers from matrix

牧云@^-^@ 提交于 2019-11-27 03:37:17
问题 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

Finding the closest integer fraction to a given random real between 0..1, given ranges of numerator and denominator

泪湿孤枕 提交于 2019-11-27 03:24:44
问题 Given two ranges of positive integers x: [1 ... n] and y: [1 ... m] and random real R from 0 to 1, I need to find the pair of elements (i,j) from x and y such that x_i / y_j is closest to R. What is the most efficient way to find this pair? 回答1: Use Farey sequence. Start with a = 0, b = 1 and A = {the closest of a and b to R}. Let c be the next Farey fraction between a and b, given by c = (num(a) + num(b))/(denom(a) + denom(b)) (make sure to divide num(c) and denom(c) by gcd(num(c), denom(c))

Best open source Mixed Integer Optimization Solver [closed]

那年仲夏 提交于 2019-11-27 03:00:58
I am using CPLEX for solving huge optimization models (more than 100k variables) now I'd like to see if I can find an open source alternative, I solve mixed integer problems (MILP) and CPLEX works great but it is very expensive if we want to scale so I really need to find an alternative or start writing our own ad-hoc optimization library (which will be painful) Any suggestion/insight would be much appreciated I personally found GLPK better (i.e. faster) than LP_SOLVE. It supports various file formats, and a further advantage is its library interface, which allows smooth integration with your

Free Optimization Library in C# [closed]

折月煮酒 提交于 2019-11-27 00:58:28
问题 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? 回答1: 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

How to find the local minima of a smooth multidimensional array in NumPy efficiently?

一世执手 提交于 2019-11-27 00:58:13
问题 Say I have an array in NumPy containing evaluations of a continuous differentiable function, and I want to find the local minima. There is no noise, so every point whose value is lower than the values of all its neighbors meets my criterion for a local minimum. I have the following list comprehension which works for a two-dimensional array, ignoring potential minima on the boundaries: import numpy as N def local_minima(array2d): local_minima = [ index for index in N.ndindex(array2d.shape) if

How can I find local maxima in an image in MATLAB?

十年热恋 提交于 2019-11-27 00:30:25
问题 I have an image in MATLAB: y = rgb2gray(imread('some_image_file.jpg')); and I want to do some processing on it: pic = some_processing(y); and find the local maxima of the output. That is, all the points in y that are greater than all of their neighbors. I can't seem to find a MATLAB function to do that nicely. The best I can come up with is: [dim_y,dim_x]=size(pic); enlarged_pic=[zeros(1,dim_x+2); zeros(dim_y,1),pic,zeros(dim_y,1); zeros(1,dim_x+2)]; % now build a 3D array % each plane will

knapsack optimization with dynamic variables

半世苍凉 提交于 2019-11-26 23:43:14
问题 I am trying to solve an optimization problem, that it's very similar to the knapsack problem but it can not be solved using the dynamic programming. The problem I want to solve is very similar to this problem: 回答1: indeed you may solve this with CPLEX. Let me show you that in OPL. The model (.mod) {string} categories=...; {string} groups[categories]=...; {string} allGroups=union (c in categories) groups[c]; {string} products[allGroups]=...; {string} allProducts=union (g in allGroups) products