Difference between revisions of "Gurobi/Example"

From ScientificComputing
Jump to: navigation, search
(Created page with "We are using the example from the gurobi website http://www.gurobi.com/documentation/7.0/quickstart_linux/solving_a_simple_model_the.html to demonstrate how to solve a simp...")
 
 
Line 15: Line 15:
 
  Manganese (Mn) 0.3g
 
  Manganese (Mn) 0.3g
  
Suppose the Mint wants to use the available materials to produce coins with the maximum total dollar value. Which coins should they produce?
+
For our example, we'll assume we have 1000 grams of copper and 50 grams of the other minerals. Suppose the Mint wants to use the available materials to produce coins with the maximum total dollar value. Which coins should they produce?
  
 
The corresponding gurobi input file looks like
 
The corresponding gurobi input file looks like

Latest revision as of 11:42, 4 April 2018

We are using the example from the gurobi website

http://www.gurobi.com/documentation/7.0/quickstart_linux/solving_a_simple_model_the.html

to demonstrate how to solve a simple model.

Imagine that it is the end of the calendar year at the United States Mint. The Mint keeps an inventory of the various minerals used to produce the coins that are put into circulation, and it wants to use up the minerals on hand before retooling for next year's coins.

The Mint produces several different types of coins, each with a different composition. The table below shows the make-up of each coin type (as reported in the US Mint coin specifications).

 	        Penny	Nickel	Dime	Quarter	Dollar
Copper (Cu)	0.06g	3.8g	2.1g	5.2g	7.2g
Nickel (Ni)	 	1.2g	0.2g	0.5g	0.2g
Zinc (Zi)	2.4g	 	 	 	0.5g
Manganese (Mn)	 	 	 	 	0.3g

For our example, we'll assume we have 1000 grams of copper and 50 grams of the other minerals. Suppose the Mint wants to use the available materials to produce coins with the maximum total dollar value. Which coins should they produce?

The corresponding gurobi input file looks like

[leonhard@eu-login-10 ~]$ cat coins.lp 
Maximize
  .01 Pennies + .05 Nickels + .1 Dimes + .25 Quarters + 1 Dollars
Subject To
  Copper: .06 Pennies + 3.8 Nickels + 2.1 Dimes + 5.2 Quarters + 7.2 Dollars -
     Cu = 0
  Nickel: 1.2 Nickels + .2 Dimes + .5 Quarters + .2 Dollars -
     Ni = 0
  Zinc: 2.4 Pennies + .5 Dollars - Zi = 0
  Manganese: .3 Dollars - Mn = 0
Bounds
  Cu <= 1000
  Ni <= 50
  Zi <= 50
  Mn <= 50
Integers
  Pennies Nickels Dimes Quarters Dollars
End
[leonhard@eu-login-10 ~]$

The job is then submitted using the gurobi command line interface:

[leonhard@eu-login-10 ~]$ bsub -n 1 -W 0:10 -R "rusage[mem=512]" "gurobi_cl ResultFile=coins.sol coins.lp"
Generic job.
Job <60506881> is submitted to queue <normal.4h>.
[leonhard@eu-login-10 ~]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
60506881   Leonhard    PEND  normal.4h  eu-login-10             * coins.lp Apr  4 13:21
[leonhard@eu-login-10 ~]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
60506881   Leonhard    RUN  normal.4h   eu-login-10 eu-ms-013-0 * coins.lp Apr  4 13:21
[leonhard@eu-login-10 ~]$ bjobs
No unfinished job found

The solution is then written to the file coins.sol:

[leonhard@eu-login-10 ~]$ cat coins.sol 
# Objective value = 113.45
Pennies 0
Nickels 0
Dimes 2
Quarters 53
Dollars 100
Cu 999.8
Ni 46.9
Zi 50
Mn 30
[leonhard@eu-login-10 ~]$

The LSF logs are written to the corresponding log file lsf.o60506881