algorithm,optimization,bin-packing
If the problem under consideration is the generalized assignment problem, it is NP-hard but admits an approximation algorithm. From a brief look, the approximation ratio depends on the approximation ratio of an approximation algorithm for the knapsack problem, which in turn admits a fully polynomial time approximation scheme. In total....
You can try that out yourself using php's microtime function: $saleprice = 1; $start = microtime(true); if(!empty($saleprice)) echo $saleprice . '<br/>'; echo 'empty: ' . number_format(( microtime(true) - $start), 30) . '<br/>'; $start = microtime(true); if(!is_null($saleprice)) echo $saleprice . '<br/>'; echo 'is_null: ' . number_format(( microtime(true) - $start), 30) ....
Your function is NOT convex, therefore you will have multiple local/global minima or maxima. For your function I would run a non traditional/ derivative free global optimizer like simulated annealing or genetic algorithm and use the output as a starting point for BFGS or any other local optimizers to get...
sql-server,join,optimization,union
Well first of all, you can use UNION ALL, which will leave out the duplication check. This will be much faster. Another suggestion is the IN() in your first SELECT. This could cause long runtimes if your subquery returns many rows. I would suggest to redesign it from this: select...
Well, obviously the compiler isn't 'smart' enough to propagate the n constant and unroll the for loop. Actually it plays it safe since arg->n can change between instantiation and usage. In order to have consistent performance across compiler generations and squeeze the maximum out of your code, do the unrolling...
python,opencv,numpy,optimization,cython
Use scipy.spatial.distance.cdist for the distance calculation in points_distance. First, optimize your code in pure Python and numpy. Then if necessary port the critical parts to Cython. Since a number of functions are called repeatedly a few ~100000 times, you should get some speed up from Cython for those parts. Unless,...
javascript,dom,optimization,asynchronous,requestanimationframe
Both types of DOM operations (read/write) have their own job queues. Each queue is flushed (e.g. all jobs in it are ran/executed) every requestAnimationFrame If you add 100 read operations all within 5ms, for example, (during a loop for instance), all of those read operations will (most likely) occur the...
You don't need a (Linked)HashMap for this job. Use a NavigableMap (TreeMap would be the standard implementation) that provides a lot of useful operations for such use-cases: floor/ceiling, higher/lower, first/last and so on. // get the value at this specific time or the last one before that Double valueAtTheTime =...
r,optimization,regression,rscript
This seems to work fine: opt1 <- optim(startparam, fn=ls,method="L-BFGS-B", Val=Val,Hi=Hi,Di=Di, lower =c(20,10,0), upper =c(100,70,25)) note that the values of Val, Hi, Di get passed through optim to the objective function....
Create a variable dummy and initialize it to argc. Then in each loop increment dummy by the return of the function. Then return dummy. This should stop the compiler from eliding the function calls.
Optim converges with your initial parameters, so I'm not sure there is a problem. But, you can also try using the alternative optimization routines and run a simple test to see what parameters are giving warnings ## Test results with other methods x1 <- optim(c(17,5,3,4,27,13),LL,method="BFGS",u=u) ps <- x1$par x2 <-...
matlab,function,optimization,parameter-passing
As far as I know, matlab does not actually copy the content of the data you pass to a function until the point when you modify it in the function itself - in which case it makes a local copy and that takes some CPU time. Therefore, as long as...
mysql,optimization,query-optimization
It is not possible to optimize a mixture of ASC and DESC, as in ORDER BY t.fecha DESC, t.idsensor ASC You tried a covering index: INDEX `sensor_temp` (`idsensor`,`fecha`,`temperatura`) However, this covering index may be better: INDEX `sensor_temp` (`fecha`,`idsensor`,`temperatura`) Then, if you are willing to get the sensors in a different...
algorithm,optimization,numerical-methods
For this setting, I'd go with Golden Section Search. Convexity implies unimodality, which is needed by this method. Conversely, this method does not need derivatives. You can find derivatives numerically, but that's another way of saying "multiple function assessments"; might as well use these for golden-section partitions. ...
Here is an answer. First remove all the branches and then implement as SSE. I haven't check the speed yet. const int T1 = 17560; const int T2 = 244583; const int SHIFT = 16; int A = 2*((dx ^ dy) >= 0)-1; //check (dy,dx) opposite sign dy = abs(dy);...
javascript,arrays,optimization,memory-management,data-structures
splice is pretty harmful for performance in a loop. But you don't seem to need mutations on the input arrays anyway - you are creating new ones and overwrite the previous values. Just do function doTransfers() { var A_pending = []; var B2_pending = []; for (var i = 0;...
Determinstic variant First a more efficient but deterministic approach: occurs_most([],_,0). occurs_most(List,X,Nr) :- msort(List,[H|T]), most_sort(T,H,1,H,1,X,Nr). most_sort([Hb|T],Ha,Na,Hb,Nb,Hr,Nr) :- !, Nb1 is Nb+1, most_sort(T,Ha,Na,Hb,Nb1,Hr,Nr). most_sort([Hc|T],_,Na,Hb,Nb,Hr,Nr) :- Nb > Na, !, most_sort(T,Hb,Nb,Hc,1,Hr,Nr). most_sort([Hc|T],Ha,Na,_,_,Hr,Nr) :- most_sort(T,Ha,Na,Hc,1,Hr,Nr). most_sort([],Ha,Na,_,Nb,Ha,Na) :- Na >= Nb, !. most_sort([],_,_,Hb,Nb,Hb,Nb). First you use msort/2 to sort the list. Then you iterate over...
It turns out the delay is the Microsoft antivirus program scanning the executable each time it's run. Disabling protection on that file cuts the time to 47 milliseconds.
java,optimization,out-of-memory,primes
There are two possibilities: You use -Xmx256M which means a 256 MB heap. But there's more than just the heap and your VM may get killed when it tries to get more. You give 256 MB to your VM but your program needs more and gets killed. <---- As RealSkeptic...
The % gap is the relative difference between the best solution and the best known bound for a solution. This is guaranteed to be higher than the gap between the best known solution and the true global optimum. In your case, the best bound is 83.9275, the best bound is...
r,optimization,circular,maximization
I would compute all the pairs of rows in df: (pairs <- cbind(1:nrow(df), c(2:nrow(df), 1))) # [,1] [,2] # [1,] 1 2 # [2,] 2 3 # [3,] 3 4 # [4,] 4 5 # [5,] 5 6 # [6,] 6 1 You can find the best pairing with which.max:...
There are a few problems with your overall process that cause trouble. First of all as @user227710 mentions in the comments you should replace && with &. These have different meanings. Now for the optimiser It looks like you want to set limits to your parameters (i.e. what is known...
performance,matlab,function,optimization,plot
The cost is coming from the calls to hermiteH -- for every call, this creates a new function using symbolic variables, then evaluates the function at your input. The key to speeding this up is to pre-compute the hermite polynomial functions then evaluate those rather than create them from scratch...
python,arrays,optimization,multidimensional-array,list-comprehension
You need a different data structure for fast lookups: dict rather than list. Here's an example: array1 = [ [[1,2], [1,5]], [[3,2], [7,5]], ] array2 = [ [[3,2], [9,9]], [[1,2], [1,5]], ] lookup = {} for r, row in enumerate(array1): for c, val in enumerate(row): pair = tuple(val) lookup[pair] =...
matlab,function,optimization,maximize
Both your functions return a vector of values whereas fminunc requires that the function returns a scalar / single value. The error is pretty clear. The function fminunc is trying to find the best solution that minimizes a cost function, so what you need to supply is a cost function....
c++,performance,gcc,optimization,compiler-optimization
For the purpose of in-memory data representation, a C++ class can have either plain or static member functions, or virtual member functions (including some virtualdestructor, if any). Plain or static member functions do not take any space in data memory, but of course their compiled code take some resource, e.g....
Like I said in my comment above, perhaps it would be best if you simply tried it and did some benchmarking. I'd expect this to depend primarily on the OS you're using. That being said, starting a new process generally is many orders of magnitude slower than calling a subroutine...
javascript,jquery,performance,function,optimization
Using your HTML with only two buttons and identical CSS The following JS works for better for me: Javascript: var newsDepth = 3; var maxNewsDepth = 3; $('#show-more-news').hide(); $('#show-more-news').click( function () { (newsDepth < maxNewsDepth ) && newsDepth++; $('#art-' + newsDepth).show(); $('#show-less-news').show(); if (newsDepth == maxNewsDepth) $('#show-more-news').hide(); }); $('#show-less-news').click( function...
By default Z3 solves the objectives one at a time and finds the lexicographically best solution. First it tries to satisfy as many soft constraints from "first". The weight you associate with the soft constraints is a penalty for not satisfying the constraint. That is, it is not an award,...
The problem was that I was installing the scip-3.1.1.tgz rather than scipoptsuite-3.1.1.tgz. Running make on scipoptsuite-3.1.1.tgz runs perfectly fine.
java,algorithm,sorting,optimization
This is an instance of the Knapsack Problem. The Wikipedia page lists a lot of known algorithm that solve this efficiently. You might want to gather some inspiration from these algorithms.
c,optimization,clang,inline,c99
At -O1 and greater it is not calling the function it just moves the code into main, we can see this by using godbolt which shows the asm as follows see it live: main: # @main pushq %rax movl $.L.str, %edi movl $42, %esi xorl %eax, %eax callq printf xorl...
Removing the viewBox creates a significant semantic difference as the SVG will no longer scale (i.e. be responsive to UA resizes). This only applies if you're viewing the image directly though if you're viewing it as a background-image or via a SVG <image> tag or html <img> tag then the...
c++,performance,optimization,x86,prefetch
If you read the description for _mm_prefetch() from the site you linked to it has : void _mm_prefetch (char const* p, int i) Fetch the line of data from memory that contains address p to a location in the cache heirarchy specified by the locality hint i. So you need...
MillenialMedia - Pretty decent engineering. Pretty good revenue Inmobi - Good revenue. Sometimes really dodgy ads. I've experiemented with half a dozen others, but they provided insignificant revenue, or provided many bugs. But your mileage may vary....
Since you mentioned "evolution strategy" in your comment to @Divkar, I am assuming you want to optmize the ackley function using any evolutionary algorithm. In fact, if this is the case and if you are familiar with the Particle Swarm Optimization (PSO) , there is a submission (among many) in...
c++,algorithm,optimization,dynamic-programming
First of all, you are right that iteratively combining the best remaining student with the worst remaining student gives you the optimum result (see proof below). However, you don't calculate the cost of that solution correctly. You have to run through all pairs of your combination in order to find...
c,linux,optimization,shared-libraries,glibc
Setting the environment variable LD_BIND_NOW should help achieving just that. Set it with export LD_BIND_NOW=1 then execute your program. Excerpt: ELF platforms (Linux, Solaris, FreeBSD, HP-UX, IRIX, etc.) support lazy binding of procedure addresses, which is an optimization that yields better performance overall but a genuine problem for applications that...
What you are looking for are nonlinear constraints, fmincon can handle it (I only know the command, not the GUI) with the argument nonlcon. For more information look at this guide http://de.mathworks.com/help/optim/ug/fmincon.html How would you implement this? First create a function function [c, ceq] = mycondition(x) c = -max(x)/min(x)/10; ceq...
php,mysql,arrays,performance,optimization
Database connections are going to be the most expensive part of the algorithm, so minimize the amount of time each connection will last. Pull it from the database and loop through the array. Unless you are doing a function that would be very quick in a database (ie- sorting on...
c#,xml,csv,optimization,type-conversion
IEnumerable<string> values = new List<string>(); values = … Probably not going to be a big deal, but why create a new List<string>() just to throw it away. Replace this with either: IEnumerable<string> values; values = … If you need values defined in a previous scope, or else just: Enumerable<string> values...
How about you use a switch/case structure to determine which function to call and what value of y to use? returnType (func*)(); // Create a function pointer and use that switch(userInput){ case 0: func = &func1; y = 5; case 1: func = &func2; y = 6; } To simplify...
If you want only the most recent comment for a given user, then you can express this as: SELECT rc.* FROM requests r JOIN requests_comments rc ON rc.request_id = r.id WHERE r.username = 'someuser' ORDER BY rc.commented_at DEC LIMIT 1; For performance, you want an index on requests(username, id) and...
javascript,jquery,optimization
Rename f() to something else that makes more sense to your domain: var f = function(indicatorClicked, remainingIndicators) { $(indicatorClicked).toggleClass("icon-caret-up icon-caret-down"); $.each(remainingIndicators, function(index, indicator) { $(indicator).removeClass("icon-caret-up").addClass("icon-caret-down"); }); } $("#IDArea1").click(function () { f('#indicator1', ['#indicator2', '#indicator3']) }); $("#IDArea2").click(function () { f('#indicator2', ['#indicator1', '#indicator3']) }); $("#IDArea3").click(function () {...
So, memcached is better and faster! BUT: memcached can remove old keys, if ttl expires or small size for sets other keys. The situation may be: In first request you set key-value to memcached. In second request (parallel) you set another key value to memcached, and in memcached small memory...
No (technically there could be a difference, since OpenGL does not impose any performance requirements on the functioncall). Btw. you should set the clear color before calling clear....
If the var<xx> variables are all multiples of ten, i.e. there are no other variables beginning with var, you can use the colon-operator, which acts as a wildcard, e.g. drop var: ; /* drop all variables beginning with 'var' */ Alternatively, you can dynamically generate a list of all the...
c,performance,opencv,optimization,sse
As harold said, delta is used to make unsigned comparsion. Let's describe this implementation by steps: __m128i x0 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[0])), delta); __m128i x1 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[4])), delta); __m128i x2 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[8])), delta); __m128i x3 = _mm_sub_epi8(_mm_loadu_si128((const __m128i*)(ptr + pixel[12])), delta); m0 =...
c,performance,optimization,alphablending,lookup-tables
Table lookup is not a panacea. It helps when the table is small enough, but in your case the table is very big. You write 16 megabytes used for the table is not an issue in this case which I think is very wrong, and is possibly the source of...
python,python-2.7,optimization,matrix
In terms of refactoring, you almost certainly want to avoid "brute force" in the sense of having to explicitly type out all your cases :) @alexmcf addresses this above. In conceptual terms, your approach follows the problem statement directly: check all neighbors for each number in the matrix and sum...
while((j < nprimos) && (num % primos[j] > 0)) ++j; One way for this while loop to terminate is when j == nprimos (when i == 0 and therefore num == 1, for instance; obviously 1 isn't divisible by any prime number.) In this case the access to primos[j] in...
java,algorithm,optimization,foreach,bubble-sort
Using indexOf is not correct, if your ArrayList x contains more than one value of i, your sort method will behave incorrectly. For example, this case: [5, 5, 1] After running your program, return [5, 5, 1] Plus, using indexOf, as mentioned by tucuxi, will slow down your program....
I am not sure what you exactly want to do, but are you aware of scipy.ndimage.measurements for computing on arrays with labels? It look like you want something like: cLoss = len(dist_) - sum(TLabels * scipy.ndimage.measurements.sum(TLabels,dist_,dist_) / len(dist_)) ...
If the functions are linear, then they will be at a minimum at the lower end of the range where beta>=0, and at the upper end of the range if beta<=0 - no need to use optimize(). It's not entirely clear what you're expecting the code to do - if...
python,numpy,optimization,fortran,f2py
The flags -xhost -openmp -fp-model strict come from def get_flags_opt(self): return ['-xhost -openmp -fp-model strict'] in the file site-packages/numpy/distutils/fcompiler/intel.py for the classes that invoke ifort. You have two options to modify the behavior of these flags: call f2py with the --noopt flag to suppress these flags call f2py with the...
Note that there are 2n-1 different such names for a string of lengh n, as there can or can not be a _ between any two characters. For your long-long name that makes 134,217,728 variants! Regardless of what algorithm you use, this will take a very long time. One way...