Integrality Gap in MAXIMIZATION in CPLEX+Java | Bug? - java

I try to solve a large MIP in which the . If it does not solve optimally, it shall return the integrality gap (that is, difference between best integer solution and best solution of the linear relaxation).
Using getMIPRelativeGap of the Java+CPLEX interface, I sometimes got values in the range of 1.0E11-1.0E13 which does not make sense, as an integrality gap should be a percentage between 0 and 1. I tracked those cases down and found out that I get those results, if the best integer solution has a value of 0 (my inner problem is a profitable tour problem, thus, if the best route is not visiting any vertice). The integrality gap should be (bestobjective-bestinteger)/bestobjective (https://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.0/ilog.odms.cplex.help/refdotnetcplex/html/M_ILOG_CPLEX_Cplex_MIPInfoCallback_GetMIPRelativeGap.htm), yet, it seems to be (bestobjective-bestinteger)/bestinteger.
I also tested a couple of other values (if the integer objective is positive), and were able to confirm this in examples.
Can someone else reproduce this behavior? Does this behavior make sense to you?
Thanks :)

Indeed, the documentation for CPXgetmiprelgap in the Callable Library (C API) says the following:
For a minimization problem, this value is computed by
(bestinteger - bestobjective) / (1e-10 + |bestinteger|)
where bestinteger is the value returned by CPXXgetobjval/CPXgetobjval
and bestobjective is the value returned by
CPXXgetbestobjval/CPXgetbestobjval. For a maximization problem,
the value is computed by:
(bestobjective - bestinteger) / (1e-10 + |bestinteger|)
So, it looks like the documentation for the Java API is buggy. The Java API just calls CPXgetmiprelgap under the hood, so it should be the same. Thanks for reporting this. I'll make sure that this gets passed on to the folks who can fix it.

Related

"Escaped hexadecimal" to boolean

I'm working with HBase on a project and running into a seemingly simple situation that is throwing me for a loop. Hbase can store table values as escaped hexadecimal. In my case, I have true/false being stored as \x00 and \xFF, respectively.
The problem is (besides being unfamiliar with Java) I need to find a way to convert these to bool, or at least to compare them in a like-bool situation. They will never be anything other than \x00 and \xFF.
Is there not an elegant way to do this?
Please help, I'm really stuck.
Edit: This is probably relevant Hbase shell - how to write byte value
I suspect you could do something like... Hex ->binary->boolean.
But there might even be a toBoolean method already.
Or you could override the compare method they're using. But this could yield undesirable effects.
Can you post the API for the class you're using?
Ok, apparently there is a Bytes.toBoolean() function.

java.math.BigDecimal.scale() equivalent for double

I've got a matrix of values like the one below that I need to scale. I've been looking around for an inbuilt function if there is one that could do this for me. I haven't found one & so have ended up writing code to do the scaling using the below formula
scaledMatrix = (Matrix - MeanMatrix)/Standard Deviation
This code is a bit buggy & I'm working on correcting it. While I do that, I happened to bump on java.math.BigDecimal.scale() & did look up an equivalent for double as the matrix I have is double type numbers
If someone could please help me with details on
1) If there is an inbuilt function that accepts matrix of values & returns me the scaled matrix
2) `java.math.BigDecimal.scale()` equivalent for `double` type data
Any help would be much appreciated please.
The BigDecimal.scale() method does not do what you seem to think it is doing. A BigDecimal value is stored as a * 10^b (where ^ denotes exponentiation). The BigDecimal.scale() method basically returns the b part of that.
I do not know of a similar method for double values, nor do I know of a method which performs the function you need. Since you put apache-commons in the tags, I suggest you look into Apache Commons's extensive statistical library.

getAvailableBlocksLong() * getBlockSizeLong() VS getAvailableBytes()

[EDIT] I did make a stupid mistake on my testing. I asked a question here without knowing it.
The answer is, both are the same. But I leave my post here for others.
What is the difference between
getAvailableBlocksLong() * getBlockSizeLong() and getAvailableBytes()?
I tested myself and got a really strange result on Genymotion.
The values from getAvailableBlocksLong() * getBlockSizeLong() and getAvailableBytes() are different!
I literally don't get what is happening here.
Does it have something to do only with Genymotion?
Should I just use getAvailableBytes() in most cases?
The former gets the number of available memory blocks and multiplies it by the memory block size, the latter just straight up returns the available momery in bytes. Same thing

Unexpected results from Metaphone algorithm

I am using phonetic matching for different words in Java. i used Soundex but its too crude. i switched to Metaphone and realized it was better. However, when i rigorously tested it. i found weird behaviour. i was to ask whether thats the way metaphone works or am i using it in wrong way. In following example its works fine:-
Metaphone meta = new Metaphone();
if (meta.isMetaphoneEqual("cricket","criket")) System.out.prinlnt("Match 1");
if (meta.isMetaphoneEqual("cricket","criketgame")) System.out.prinlnt("Match 2");
This would Print
Match 1
Mathc 2
Now "cricket" does sound like "criket" but how come "cricket" and "criketgame" are the same. If some one would explain this. it would be of great help.
Your usage is slightly incorrect. A quick investigation of the encoded strings and default maximum code length shows that it is 4, which truncates the end of the longer "criketgame":
System.out.println(meta.getMaxCodeLen());
System.out.println(meta.encode("cricket"));
System.out.println(meta.encode("criket"));
System.out.println(meta.encode("criketgame"));
Output (note "criketgame" is truncated from "KRKTKM" to "KRKT", which matches "cricket"):
4
KRKT
KRKT
KRKT
Solution: Set the maximum code length to something appropriate for your application and the expected input. For example:
meta.setMaxCodeLen(8);
System.out.println(meta.encode("cricket"));
System.out.println(meta.encode("criket"));
System.out.println(meta.encode("criketgame"));
Now outputs:
KRKT
KRKT
KRKTKM
And now your original test gives the expected results:
Metaphone meta = new Metaphone();
meta.setMaxCodeLen(8);
System.out.println(meta.isMetaphoneEqual("cricket","criket"));
System.out.println(meta.isMetaphoneEqual("cricket","criketgame"));
Printing:
true
false
As an aside, you may also want to experiment with DoubleMetaphone, which is an improved version of the algorithm.
By the way, note the caveat from the documentation regarding thread-safety:
The instance field maxCodeLen is mutable but is not volatile, and accesses are not synchronized. If an instance of the class is shared between threads, the caller needs to ensure that suitable synchronization is used to ensure safe publication of the value between threads, and must not invoke setMaxCodeLen(int) after initial setup.

JDK 1.6 GC AdaptiveSizeThroughPutPolicy

Please explain the detailed meaning of VALUE used in the GC option :
-XX:AdaptiveSizeThroughPutPolicy
By default value given is 0.
Does this VALUE imply - the number of steps to use heuristics before real data is used?. What are implications of using a high(eg: 50 or 100) or low value (eg: 0)
The best way I know to understand those arcane options is going directly to the source:
psAdaptiveSizePolicy.cpp
It seems that 1 and !=1 are the only valid choices.
-XX:AdaptiveSizeThroughPutPolicy=1 is used in coordination with -XX:AdaptiveSizePolicyInitializingSteps=VALUE.

Categories

Resources