Saturday, March 1, 2014

Keyboard shortcuts Eclipse

Debug Mode in Eclipse for Source Not Found
"window->Preferences->Java->Debug" and disable the "suspend execution of uncaught exceptions"
http://stackoverflow.com/questions/10121214/has-myeclipse-implicit-breakpoint-in-debugging-mode-in-class-urlclasspath

If I'm reading you right, you want to specify some classes that you 
don't want to step into? I think what you want is...

Window -> Preferences -> Java -> Debug -> Step Filtering
http://www.eclipse.org/forums/index.php/t/101609/

Task Windows (Windows>Show View>Tasks, find Todo in Eclipse)
See the following on how to change configure Task Windows
http://www.mooreds.com/wordpress/archives/446

Add shortcut key to bookmarks
Windows>preference>Key>search for "add bookmark"
set alt+b (in windows)
http://stackoverflow.com/questions/3141493/bookmarks-in-eclipse-set-and-go-using-hotkeys-do-they-exist

Adding bookmark / Open bookmark windows
http://sandarenu.blogspot.sg/2008/02/using-bookmarks-in-eclipse.html

Finding classes/packages (ctrl+shift+h)
http://stackoverflow.com/questions/8944994/how-to-find-package-by-name-in-eclipse

Find usage (ctrl+shift+g)

Find type declaration (ctrl+g)

Eclipse Shortcut (alt+left arrow)

Generate Constructor (Alt+Shift+S, O)
http://www.eclipseonetips.com/2010/03/08/generate-class-constructors-in-eclipse-based-on-fields-or-superclass-constructors/

includes import
ctrl+shift+o

Open file in explorer
http://basti1302.github.io/startexplorer/

Formatting code
ctrl+shift+f

Formatting code upon save
http://www.eclipseonetips.com/2009/12/13/automatically-format-and-cleanup-code-every-time-you-save/

Automatic put semicolon at the end
http://www.eclipseonetips.com/2010/02/22/place-a-semicolon-at-the-end-of-a-java-statement-in-eclipse/

Duplicate Lines
Ctrl-Alt-Down: copies current line or selected lines to below
Ctrl-Alt-Up:: copies current line or selected lines to above
Ctrl-Shift-L: brings up a List of shortcut keys

Rename variable
ALT+SHIFT+R 


Time different
long beginTime = System.currentTimeMillis();

//Some operations. Let us asssume some database operations etc. which are time consuming.

//

long endTime = System.currentTimeMillis();

long difference = endTime - beginTime;


I prefer visual presentation:
╔══════════════╦═════════════════════╦═══════════════════╦══════════════════════╗
║   Property   ║       HashMap       ║      TreeMap      ║     LinkedHashMap    ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║              ║  no guarantee order ║ sorted according  ║                      ║
║   Order      ║ will remain constant║ to the natural    ║    insertion-order   ║
║              ║      over time      ║    ordering       ║                      ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║  Get/put     ║                     ║                   ║                      ║
║   remove     ║         O(1)        ║      O(log(n))    ║         O(1)         ║
║ containsKey  ║                     ║                   ║                      ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║              ║                     ║   NavigableMap    ║                      ║
║  Interfaces  ║         Map         ║       Map         ║         Map          ║
║              ║                     ║    SortedMap      ║                      ║
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
║              ║                     ║                   ║                      ║
║     Null     ║       allowed       ║    only values    ║       allowed        ║
║ values/keys  ║                     ║                   ║                      ║
╠══════════════╬═════════════════════╩═══════════════════╩══════════════════════╣
║              ║   Fail-fast behavior of an iterator cannot be guaranteed       ║
║   Fail-fast  ║ impossible to make any hard guarantees in the presence of      ║
║   behavior   ║           unsynchronized concurrent modification               ║
╠══════════════╬═════════════════════╦═══════════════════╦══════════════════════╣
║              ║                     ║                   ║                      ║
║Implementation║      buckets        ║   Red-Black Tree  ║    double-linked     ║
║              ║                     ║                   ║       buckets        ║
╠══════════════╬═════════════════════╩═══════════════════╩══════════════════════╣
║      Is      ║                                                                ║
║ synchronized ║              implementation is not synchronized                ║
╚══════════════╩════════════════════════════════════════════════════════════════╝

http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

Tuesday, February 18, 2014

How to use Gurobi Solver

public static GRBEnv env; //Set up The Environment

public static void initialize()
        {
            env = new GRBEnv("mip1.log");
            env.Set(GRB.IntParam.LogToConsole, 0);
            init = true;
        }

 GRBModel model = new GRBModel(env); //Set up The Model
 sv.decisionVar = model.AddVar(0.0, 1.0, 0.0, GRB.BINARY, sv.decisionVarName); //Create Decision Var
model.Update(); //Update the model after adding variable

GRBLinExpr decisionVarExpr =null;
If(i==0){
decisionVarExpr=decisionvar;
}else{
           decisionVarExpr.AddTerm(1, decisionvar);//Accumulate Decision Var
}

 model.AddConstr(decisionVarExpr == 1, "decision" + j);//Add Constraint


GRBLinExpr objectiveFunction=..
 model.SetObjective(objectiveFunction, GRB.MAXIMIZE); //Set Objective Function
 model.Optimize();//Optimize it

  int status = model.Get(GRB.IntAttr.Status); //Get the overall Status
            if (status == GRB.Status.INFEASIBLE)
            {
                resultString = "";
                return false;
            }

objectiveFunction.Value // See the value of Objective function
decisionVar.Get(GRB.DoubleAttr.X).ToString() == "1" // See the value of a decision variable that has been created before


why is np in pspace?

Pspace: 
PSPACE is the set of all decision problems that can be solved by a Turing machine using a polynomial amount of space.

from http://en.wikipedia.org/wiki/PSPACE

Reason:
From: http://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/09PSPACE.pdf





Differentiate p np np-hard and np-complete problems

P: A decision problem that can be solved in polynomial time. That is, given an instance of the problem, the answer yes or no can be decided in polynomial time.

NP: A decision problem where instances of the problem for which the answer is yes have proofs that can be verified in polynomial time (We know the answer, and verified the answer takes polynomial time). This means that if someone gives us an instance of the problem and a certificate (sometimes called a witness) to the answer being yes, we can check that it is correct in polynomial time.

NP-complete: An NP problem X for which it is possible to reduce any other NP problem Y to X in polynomial time  (Any NP Problem can reduce to NP-Complete in polynonial time). Intuitively this means that we can solve Y quickly if we know how to solve X quickly. 

What makes NP-complete problems important is that if a deterministic polynomial time algorithm can be found to solve one of them, every NP problem is solvable in polynomial time (one problem to rule them all).

NP-hard: Intuitively these are the problems that are even harder than the NP-complete problems. Note that NP-hard problems do not have to be in NP (they do not have to be decision problems). The precise definition here is that a problem X is NP-hard if there is an NP-complete problem Y such that Y is reducible to X in polynomial time (Any NP-Complete problem can reduce to NP-Hard in polynonial time).

But since any NP-complete problem can be reduced to any other NP-complete problem in polynomial time, all NP-complete problems can be reduced to any NP-hard problem in polynomial time. Then if there is a solution to one NP-hard problem in polynomial time, there is a solution to all NP problems in polynomial time.


  
• P: The complexity class of decision problems that can be solved on a deterministic Turing machine in polynomial time.
• NP: The complexity class of decision problems that can be solved on a non-deterministic Turing machine in polynomial time.