optimization

Bin-packing (or knapsack?) problem

我们两清 提交于 2020-01-02 05:08:05
问题 I have a collection of 43 to 50 numbers ranging from 0.133 to 0.005 (but mostly on the small side). I would like to find, if possible, all combinations that have a sum between L and R, which are very close together.* The brute-force method takes 2 43 to 2 50 steps, which isn't feasible. What's a good method to use here? Edit: The combinations will be used in a calculation and discarded. (If you're writing code, you can assume they're simply output; I'll modify as needed.) The number of

Mathematica: Evaluation order during numerical optimisation of black box functions

大憨熊 提交于 2020-01-02 03:54:07
问题 I am attempting to perform a numerical optimisation of a "black box" function in Mathematica. Schematically it goes like this: NMinimize[{comb[x,y,z], x > 0}, {x,y,z}] where comb[x,y,z] is defined similarly to this: comb[x_,y_,z_] := Module[{}, Print[x,y,z]; M = FindMaximum[SkewNormal[a,x,y,z], {a,x}] // First; val = f[x,y,z,M]; Return[val]; ]; However, all of the minimisation functions I have tried seem to not immediately provide comb[x,y,z] with numerical values, and it ends up trying to

Optimize my performance

我是研究僧i 提交于 2020-01-02 03:46:13
问题 I'm working on a project with Zend Framework 1.11, Doctrine 2, some Symfony 2 componenents and others tools & libraries. I'm trying to optimize performance using Xdebug & Webgrind. I've already found some bottlenecks like parsing Ini config, etc.. and cached that. Now, I just realize that the autoloading is the most costly part of my application: Opl\Autoloader\ApcLoader->loadClass 274 31.36 43.86 Zend_Loader_PluginLoader->load 150 4.80 12.29 Zend_Loader_Autoloader->getClassAutoloaders 278 1

Fast searching for the lowest value greater than x in a sorted vector

北慕城南 提交于 2020-01-02 03:43:11
问题 Fast means better than O(N), which is as good as find() is capable of. I know there is ismembc and ismembc2 , but I don't think either of them are what I am looking for. I read the documentation and it seems they search for a member equal to x, but I want the index of first value greater than x. Now if either of these functions is capable of doing this, could somebody please give an example, because I can't figure it out. Ideal behaviour: first_greater_than([0, 3, 3, 4, 7], 1) returns 2, the

Python: Nested for loops or “next” statement

眉间皱痕 提交于 2020-01-02 03:39:12
问题 I'm a rookie hobbyist and I nest for loops when I write python, like so: dict = { key1: {subkey/value1: value2} ... keyn: {subkeyn/valuen: valuen+1} } for key in dict: for subkey/value in key: do it to it I'm aware of a "next" keyword that would accomplish the same goal in one line (I asked a question about how to use it but I didn't quite understand it). So to me, a nested for loop is much more readable. Why, then do people use "next"? I read somewhere that Python is a dynamically-typed and

Java optimizer and redundant array evaluations

房东的猫 提交于 2020-01-02 03:34:07
问题 This is a very basic question about the Java optimization. If you have a simple for loop to iterate through an array and use array.length in the header of the loop rather than evaluating it before so that you do it only once (which is what I almost always do): for(int i=0; i<array.length;i++) { ... } Can the statement be optimized so that the JVM knows whether the array is changing for the duration of the loop so that it does not reevaluate array.length every time? 回答1: if another thread is

VS2008 binary 3x times slower than VS2005?

大憨熊 提交于 2020-01-02 03:33:04
问题 I've just upgraded a native C++ project from VS2005-SP1 to VS2008-SP1 The first thing I tested was a very basic functionality test of the application and the first thing I noticed is that the main number-crunching algorithm performs three times slower in the VS2008 binary. I tested again the VS2005 binary to make sure there isn't any other difference and it still performed as it did before. Did anyone stumble into this? 回答1: Strangest. Thing. Ever. It seems that the project upgrade wizard of

SSE2: How To Load Data From Non-Contiguous Memory Locations?

▼魔方 西西 提交于 2020-01-02 03:26:10
问题 I'm trying to vectorize some extremely performance critical code. At a high level, each loop iteration reads six floats from non-contiguous positions in a small array, then converts these values to double precision and adds them to six different double precision accumulators. These accumulators are the same across iterations, so they can live in registers. Due to the nature of the algorithm, it's not feasible to make the memory access pattern contiguous. The array is small enough to fit in L1

Can compiler reorder code over calls to std::chrono::system_clock::now()?

∥☆過路亽.° 提交于 2020-01-02 03:26:09
问题 While playing with VS11 beta I noticed something weird: this code couts f took 0 milliseconds int main() { std::vector<int> v; size_t length =64*1024*1024; for (int i = 0; i < length; i++) { v.push_back(rand()); } uint64_t sum=0; auto t1 = std::chrono::system_clock::now(); for (size_t i=0;i<v.size();++i) sum+=v[i]; //std::cout << sum << std::endl; auto t2 = std::chrono::system_clock::now(); std::cout << "f() took " << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << "

Fast count() intersection of two string arrays

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-02 03:17:34
问题 I need to count the number of elements corresponding to the intersection of two big arrays of strings and do it very fast. I am using the following code: arr1[i].Intersect(arr2[j]).Count() For CPU Time, VS Profiler indicates 85.1% in System.Linq.Enumerable.Count() 0.3% in System.Linq.Enumerable.Intersect() Unfortunately it might to take hours to do all work. How to do it faster? 回答1: You can use HashSet with arr2 HashSet<string> arr2Set = new HashSet<string>(arr2); arr1.Where(x=>arr2Set