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.



Thursday, February 6, 2014

Selenium in Google Chrome

In this tutorial, we will be going through the process of using Selenium Server (previously Selenium RC Server) to make the recorded trace to be able to run in chrome.


Download Selenium IDE (firefox plugin), it is to record the actions of firefox.

Download Selenium Server (selenium-server-standalone-2.39.0.jar), and Selenium Client (selenium-java-2.39.0.zip, link is below the Selenium Client & WebDriver Language Bindings).

Selenium IDE (firefox plugin) [Record the trace from firefox]
1.       1. In firefox, go to Selenium IDE.
2.       2. Click record to record the action
3.       3. File>Export Test Case as>Java|JUnit 4|Remote Control

Selenium Server (Running of JUnit test cases exported by Selenium IDE) [Replay the trace in Google Chrome]
1.       1. Open Eclipse, Create a Java Project, Add the Java Source file in (we will fix later)
2.       2. Configure Path - Right Click on the Project on left panel, and Select Build Path>Configure Build Path, Add JUnit, and two jar files in

3.    3. Open in Google chromeIn the selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.baidu.com/");
to
selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.baidu.com/");

4. Run it - Run the java file, it should prompt the chrome, and after running, it will prompts the status of the junit test cases.

P/S: Aside from SeleniumHQ, You may wish to lookout for iMacros for chrome

https://chrome.google.com/webstore/detail/imacros-for-chrome/cplklnmnlbnpmjogncfgfijoopmnlemp/details


===Self Reference===
To Try
1.       Capture Screenshot
selenium.captureScreenshot("C:\\a.jpg");
2.       To make it slower

selenium.waitForPageToLoad("30000"); or using slow flag

How to check page size for pdf in Acrobat Reader

File>properties,
under Description tab

Regarding changing page size, see here
http://tex.stackexchange.com/questions/156873/change-paper-size-in-winedt

How to check all fonts are embedded in pdf in Acrobat Reader

File>properties
Go to Font types tab

Make sure for all fonts, there are Embedded Subset beside it.


See How to embed all fonts in WinEdt