I can't find a way to efficiently use MIP starts in CPLEX java API.
I have a linear problem that I need to solve many times by changing just one constraint or changing the objective so I thought that starting from a solution (with MIP starts) could be a good way to speed up the calculations.
So in order to do that, after the first time I solve the problem, I save all variables in an array of IloNumVar and double that I pass to my other cplex objects with cplex.addMIPStart.
The problem is it doesn't speed up anything it makes it slower and gives me this message :
Warning: No solution found from 1 MIP starts.
So maybe I shouldn't give the MIP start all the variables but how do I know what variables to give it ?
I also tried to change the MIP start effort but it does not seem to make any difference ...
Why doesn't it make calculations faster ? Is there a better way to solve many problems that have just a few differences ?
This message usually means that you either haven't specified values for enough decision variables in your model, or the values you have given to cplex aren't feasible. You can check feasibility by using IloNumVar.setBounds on the variables then trying to solve the model. If that comes up infeasible, then you can write an iis file.
CPLEX tries, but isn't able to make use of your mipstart, so it runs slower. A good MIP start can improve the solution time dramatically, especially if cplex has a hard time finding a first-feasible solution and your MIP start has an objective function value that is close to optimal, but for many instances, it doesn't make any difference. Warm starting MIPs is much harder than warm-starting LPs.
Related
I am currently working on modelling a certain MIP in gurobi (working in java).
This problem requires a lot of computational time and I don't want to waste more than 100s on each problem. However, when this time limit is reached, I want gurobi to print the best feasable solution it has found within these 100s. I tried using the attribute ObjBound, but this always gives me a lower objective than when I let gurobi find the optimale solution (my problem is a minimization problem). So I'm guessing here that this ObjBound gives a lower bound, while I'm trying to find an upper bound.
Is there any way I can accomplish this?
If you are simply looking to get any feasible solution (not the optimal, just feasbile), set the MIPFocus parameter to 1. This tells gurobi to concentrate on finding a feasible solution rather than an optimal solution.
model.setParam('MIPFocus', 1)
model.optimize()
We have market data handlers which publish quotes to KDB Ticker Plant. We use exxeleron q java libary for this purpose. Unfortunately latency is quite high: hundreds milliseconds when we try to insert a batch of records. May you suggest some latency tips for KDB + Java binding, as we need to publish quite fast.
There's not enough information in this message to give a fully qualified response, but having done the same with Java+KDB it really comes down to eliminating the possibilities. This is common sense, really, nothing super technical.
make sure you're inserting asynchronously
Verify it's exxeleron q java that is causing the latency. I don't think there's 100's of millis overhead there.
Verify the CPU that your tickerplant is on isn't overloaded. Consider re-nicing, core binding, etc
Analyse your network latencies. Also, if you're using Linux, there's a few tcp tweaks you can try, e.g. TCP_QUICKACK
As you're using Java, be smarter about garbage collection. It's highly configurable, although not directly controllable.
if you find out the tickerplant is the source of latency, you could either recode it to not write to disk - or get a faster local disk.
There's so many more suggestions, but the question is a bit too ambiguous.
EDIT
Back in 2007, with old(ish) servers and a very old version of KDB+ we were managing an insertion rate of 90k rows per second using the vanilla c.java. That was after many rounds of the above points. I'm sure you can achieve way more now, it's a matter of finding where the bottlenecks are and fixing them one by one.
Make sure the data publish to ticket plant are is batch, like wait for a little bit to insert say few rows of data in batch, but not insert row by row once any new records coming
I'm working on a real-time game application. Most of it is written in Java, but recently I decided to experiment with moving some of the initialization procedures into JRuby scripts in order to maximize the ease for the player to modify how the world is generated.
As a start, I decided to move the map generation into a JRuby script. At present, this boils down to the following Java code:
ScriptingContainer container = new ScriptingContainer();
container.put("$data", dataPackage);
container.runScriptlet(PathType.RELATIVE, scriptName);
dataPackage = (BlockMapGenerationDataPackage)container.get("$data");
The data package contains all the information necessary for the Java program to produce the final terrain and render it, and it also contains the necessary data in order for the Ruby script to be able to craft all manner of maps. In particular, it contains a rather large array (currently 1000 x 1000 x 15). To test whether the Ruby script was working, I've stripped out the entire map generation algorithm and put in the following extremely simple test:
require 'java'
Dir["../../dist/\*.jar"].each { |jar| require jar }
for i in (0...$data.getWidth())
for j in (0...$data.getDepth())
$data.blocks[i][j][0] = Java::BlockMap::BlockType::GRASS
end
end
This is executed only once upon initialization. Now when this was all implemented in Java, with far more memory intensive generation algorithms, there were no performance or memory issues of any kind. The game ran smoothly at hundreds of frames per second at very high resolutions on an old laptop with a 1000 x 1000 x 15 map. However, when the Java generation code is replaced by the above JRuby script, the program appears to suffer some memory consumption issues: the frame rate drops by about 30-40 fps and the program freezes for maybe a 10th of a second at an impressively consistent periodic rate of about once every three seconds. Profiling and various tests reveal that the only possible culprit is the Ruby script.
Moreover, if the size of the map is drastically reduced, say to 100 x 100 x 15, then these issues more or less disappear.
I've tried various things like adding container.terminate(); or container.clear(); after the Java code to execute the script, but I really don't understand the source of the issue or how to fix it. I'd greatly appreciate if someone could explain what's going wrong here and whether or not this can be fixed!
It might be best to make the map creation routine a separate app altogether that chains to the java app.
I'm pretty sure that the memory layout of arrays in JRuby is going to be different and that could be causing your problems--The map object itself may be created with a different memory layout that is requiring some ongoing JRuby interaction whenever it is accessed, or it could be something as simple as creating Integers instead of ints and you aren't noticing it because of autoboxing (Again, TOTAL guess since I can't see data types)
You should at least experiment with the order of the subscripts: [i][j][0] compared to [0][i][j] and [0][j][i].
I want to ask a complex question.
I have to code a heuristic for my thesis. I need followings:
Evaluate some integral functions
Minimize functions over an interval
Do this over thousand and thousand times.
So I need a faster programming language to do these jobs. Which language do you suggest? First, I started with Java, but taking integrals become a problem. And I'm not sure about speed.
Connecting Java and other softwares like MATLAB may be a good idea. Since I'm not sure, I want to take your opinions.
Thanks!
C,Java, ... are all Turing complete languages. They can calculate the same functions with the same precision.
If you want achieve performance goals use C that is a compiled and high performances language . Can decrease your computation time avoiding method calls and high level features present in an interpreted language like Java.
Anyway remember that your implementation may impact the performances more than which language you choose, because for increasing input dimension is the computational complexity that is relevant ( http://en.wikipedia.org/wiki/Computational_complexity_theory ).
It's not the programming language, it's probably your algorithm. Determine the big0 notation of your algorithm. If you use loops in loops, where you could use a search by a hash in a Map instead, your algorithm can be made n times faster.
Note: Modern JVM's (JDK 1.5 or 1.6) compile Just-In-Time natively (as in not-interpreted) to a specific OS and a specific OS version and a specific hardware architecture. You could try the -server to JIT even more aggressively (at the cost of an even longer initialization time).
Do this over thousand and thousand times.
Are you sure it's not more, something like 10^1000 instead? Try accurately calculating how many times you need to run that loop, it might surprise you. The type of problems on which heuristics are used, tend to have a really big search space.
Before you start switching languages, I'd first try to do the following things:
Find the best available algorithms.
Find available implementations of those algorithms usable from your language.
There are e.g. scientific libraries for Java. Try to use these libraries.
If they are not fast enough investigate whether there is anything to be done about it. Is your problem more specific than what the library assumes. Are you able to improve the algorithm based on that knowledge.
What is it that takes so much/memory? Is this realy related to your language? Try to avoid observing JVM start times instead of the time it performed calculation for you.
Then, I'd consider switching languages. But don't expect it to be easy to beat optimized third party java libraries in c.
Order of the algorithm
Tipically switching between languages only reduce the time required by a constant factor. Let's say you can double the speed using C, but if your algorithm is O(n^2) it will take four times to process if you double the data no matter the language.
And the JVM can optimize a lot of things getting good results.
Some posible optimizations in Java
If you have functions that are called a lot of times make them final. And the same for entire classes. The compiler will know that it can inline the method code, avoiding creating method-call stack frames for that call.
I need simple opinion from all Guru!
I developed a program to do some matrix calculations. It work all fine with
small matrix. However when I start calculating BIG thousands column row matrix. It
kills the speed.
I was thinking to do processing on each row and write the result in a file then free the
memory and start processing 2nd row and write in a file, so and so forth.
Will it help in improving speed? I have to make big changes to implement this change. Thats
why I need your opinion. What do you think?
Thanks
P.S: I know about colt and Jama matrix. I can not use these packages due to company
rules.
Edited
In my program I am storing all the matrix in 2 dimensional array and if matrix is small it is fine. However, when it has thousands column and rows. Then storing all this matrix in memory for calculation cause performance issues. Matrix contains floating values. For processing I read all the matrix store in memory then start calculation. After calculating I write the result in a file.
Is memory really your bottleneck? Because if it isn't, then stopping to write things out to a file is always going to be much, much slower than the alternative. It sounds like you are probably experiencing some limitation of your algorithm.
Perhaps you should consider optimising the algorithm first.
And as I always say for all performance issue - asking people is one thing, but there is no substitute for trying it! Opinions don't matter if the real-world performance is measurable.
I suggest using profiling tools and timing statements in your code to work out exactly where your performance problem is before your start making changes.
You could spend a long time 'fixing' something that isn't the problem. I suspect that the file IO you suggest would actually slow your code down.
If your code effectively has a loop nested within another loop to process each element then you will see your speed drop away quickly as you increase the size of the matrix. If so, an area to look at would be processing your data in parallel, allowing your code to take advantage of multiple CPUs/cores.
Consider a more efficient implementation of a sparse matrix data structure and not a multidimensional array (if you are using one now)
You need to remember that perfoming an NxN multipled by an NxN takes 2xN^3 calculations. Even so it shouldn't take hours. You should get an inprovement by transposing the second matrix (about 30%) but it really shouldn't be taking hours.
So as you 2x N you increase the time by 8x. Worse than that a matrix which fit into your cache is very fast but mroe than a few MB and they have to come from main memory which slows down your operations by another 2-5x.
Putting the data on disk will really slow down your calaculation, I only suggest you do this if you martix doesn't fit in memory, but it will make it 10x - 100x slower so buying a little more memory is a good idea. (In your case your matrixies should be small enough to fit into memory)
I tried Jama, which is a very basic library which use two dimensional arrays instead of one and on 4 year old labtop took 7 minutes. You should be able to get half this time by just using the latest hardware and with multiple threads cut this below one minute.
EDIT: Using a Xeon X5570, Jama multiplied two 5000x5000 matrices in 156 seconds. Using a parallel implementation I wrote, cut this time to 27 seconds.
Use the profiler in jvisualvm in the JDK to identify where the time is spent.
I would do some simple experiments to identify how your algoritm scales, because it sounds like you might use one that has a higher runtime complexity than you think. If it runs in N^3 (which is common if you want to multiply a list with an array) then doubling the input size will eight-double the run time.