Skip to content

Commit

Permalink
Bug fixes for load_problem and printing $n = 50$
Browse files Browse the repository at this point in the history
  • Loading branch information
Foggalong committed Apr 16, 2024
1 parent 2372d36 commit 1cd5d31
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 54 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"gurobipy",
"hendo",
"linalg",
"loadtxt",
"mathbb",
"mathcal",
"mubar",
Expand Down
99 changes: 45 additions & 54 deletions robust-genetics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"source": [
"import numpy as np # defines matrix structures\n",
"from qpsolvers import solve_qp # used for quadratic optimization\n",
"from time import perf_counter # fine grained timing \n",
"import gurobipy as gp # Gurobi optimization interface (1)\n",
"from gurobipy import GRB # Gurobi optimization interface (2)"
]
Expand Down Expand Up @@ -312,7 +311,7 @@
" 7 -8.12500000e-01 -8.12500040e-01 0.00e+00 2.78e-17 1.01e-08 0s\n",
" 8 -8.12500000e-01 -8.12500000e-01 2.22e-16 5.55e-17 1.01e-11 0s\n",
"\n",
"Barrier solved model in 8 iterations and 0.02 seconds (0.00 work units)\n",
"Barrier solved model in 8 iterations and 0.03 seconds (0.00 work units)\n",
"Optimal objective -8.12500000e-01\n",
"\n",
"w = [0.50000 0.37500 0.12500]\n"
Expand Down Expand Up @@ -556,7 +555,7 @@
" E = np.loadtxt(E_filename) \n",
" # A and S are stored by coordinates so need special loader\n",
" A = load_symmetric_matrix(A_filename, dimension)\n",
" S = load_symmetric_matrix(A_filename, dimension)\n",
" S = load_symmetric_matrix(S_filename, dimension)\n",
"\n",
" return A, E, S, dimension"
]
Expand All @@ -570,14 +569,13 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Set parameter TimeLimit to value 300\n",
"Set parameter TimeLimit to value 300\n",
"Set parameter MIPGap to value 0.05\n",
"Set parameter MIPGap to value 0.05\n",
Expand Down Expand Up @@ -632,82 +630,75 @@
"Thread count: 4 physical cores, 8 logical processors, using up to 8 threads\n",
"\n",
"Optimize a model with 5 rows, 51 columns and 101 nonzeros\n",
"Model fingerprint: 0x071a27ab\n",
"Model fingerprint: 0x8c48581e\n",
"Model has 1275 quadratic objective terms\n",
"Model has 50 quadratic constraints\n",
"Coefficient statistics:\n",
" Matrix range [1e+00, 1e+00]\n",
" QMatrix range [3e-02, 1e+00]\n",
" QMatrix range [7e-06, 1e+00]\n",
" Objective range [7e-01, 1e+00]\n",
" QObjective range [5e-02, 1e+00]\n",
" Bounds range [0e+00, 0e+00]\n",
" RHS range [5e-01, 5e-01]\n",
"Presolve removed 3 rows and 0 columns\n",
"\n",
"Continuous model is non-convex -- solving as a MIP\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Presolve removed 3 rows and 0 columns\n",
"Presolve time: 0.01s\n",
"Presolved: 2552 rows, 1327 columns, 7600 nonzeros\n",
"Presolved model has 1275 quadratic objective terms\n",
"Presolved model has 1 quadratic constraint(s)\n",
"Presolved model has 1275 bilinear constraint(s)\n",
"Variable types: 1327 continuous, 0 integer (0 binary)\n",
"Found heuristic solution: objective -0.9813765\n",
"Found heuristic solution: objective -0.9763584\n",
"\n",
"Root relaxation: objective -1.951380e+00, 22 iterations, 0.00 seconds (0.00 work units)\n",
"Root relaxation: objective -1.285097e+00, 31 iterations, 0.00 seconds (0.00 work units)\n",
"\n",
" Nodes | Current Node | Objective Bounds | Work\n",
" Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time\n",
"\n",
" 0 0 -1.95138 0 - -0.98138 -1.95138 98.8% - 0s\n",
" 0 0 -1.22411 0 60 -0.98138 -1.22411 24.7% - 0s\n",
" 0 0 -1.10235 0 1007 -0.98138 -1.10235 12.3% - 0s\n",
" 0 0 -1.04576 0 6 -0.98138 -1.04576 6.56% - 1s\n",
" 0 0 - 0 -0.98138 -1.03026 4.98% - 1s\n",
" 0 0 -1.28510 0 36 -0.97636 -1.28510 31.6% - 0s\n",
" 0 0 -1.13066 0 69 -0.97636 -1.13066 15.8% - 0s\n",
" 0 0 -1.05344 0 51 -0.97636 -1.05344 7.89% - 0s\n",
" 0 0 - 0 -0.97636 -1.02501 4.98% - 0s\n",
"\n",
"Cutting planes:\n",
" RLT: 74\n",
" RLT: 6\n",
"\n",
"Explored 1 nodes (10926 simplex iterations) in 1.47 seconds (1.54 work units)\n",
"Explored 1 nodes (1828 simplex iterations) in 0.34 seconds (0.10 work units)\n",
"Thread count was 8 (of 8 available processors)\n",
"\n",
"Solution count 1: -0.981376 \n",
"Solution count 1: -0.976358 \n",
"\n",
"Optimal solution found (tolerance 5.00e-02)\n",
"Best objective -9.813764713883e-01, best bound -1.030264415192e+00, gap 4.9816%\n",
"Best objective -9.763583540500e-01, best bound -1.025012483088e+00, gap 4.9832%\n",
" i w_std w_rbs \t\t i w_std w_rbs\n",
"00 0.00000 0.00166\t 25 0.00000 0.00117\n",
"01 0.08319 0.08037\t 26 0.00000 0.00103\n",
"02 0.11649 0.11202\t 27 0.00000 0.00146\n",
"03 0.00000 0.00147\t 28 0.00000 0.00172\n",
"04 0.00000 0.00145\t 29 0.00000 0.00160\n",
"05 0.00000 0.00197\t 30 0.00000 0.00153\n",
"06 0.00000 0.00170\t 31 0.03580 0.03379\n",
"07 0.06817 0.06644\t 32 0.08447 0.07960\n",
"08 0.00000 0.00115\t 33 0.00000 0.00123\n",
"09 0.03762 0.03510\t 34 0.00000 0.00157\n",
"10 0.00000 0.00215\t 35 0.02849 0.02657\n",
"11 0.00000 0.00160\t 36 0.13489 0.13057\n",
"12 0.00000 0.00099\t 37 0.07446 0.07200\n",
"13 0.00355 0.00145\t 38 0.00000 0.00115\n",
"14 0.11542 0.10984\t 39 0.00000 0.00128\n",
"15 0.06966 0.06623\t 40 0.00000 0.00162\n",
"16 0.00000 0.00158\t 41 0.07312 0.07115\n",
"17 0.00000 0.00122\t 42 0.00000 0.00186\n",
"18 0.00000 0.00206\t 43 0.00000 0.00173\n",
"19 0.00000 0.00183\t 44 0.01336 0.00807\n",
"20 0.00000 0.00181\t 45 0.00000 0.00221\n",
"21 0.00001 0.00199\t 46 0.00000 0.00116\n",
"22 0.00000 0.00157\t 47 0.02593 0.02323\n",
"23 0.00000 0.00132\t 48 0.00000 0.00140\n",
"24 0.03537 0.03074\t 49 0.00000 0.00158\n"
"00 0.00000 0.00002\t 01 0.08319 0.08339\n",
"02 0.11649 0.11508\t 03 0.00000 0.00001\n",
"04 0.00000 0.00002\t 05 0.00000 0.00002\n",
"06 0.00000 0.00001\t 07 0.06817 0.06830\n",
"08 0.00000 0.00001\t 09 0.03762 0.03701\n",
"10 0.00000 0.00002\t 11 0.00000 0.00002\n",
"12 0.00000 0.00001\t 13 0.00355 0.00564\n",
"14 0.11542 0.11450\t 15 0.06966 0.06913\n",
"16 0.00000 0.00006\t 17 0.00000 0.00001\n",
"18 0.00000 0.00002\t 19 0.00000 0.00003\n",
"20 0.00000 0.00002\t 21 0.00001 0.00062\n",
"22 0.00000 0.00017\t 23 0.00000 0.00004\n",
"24 0.03537 0.03493\t 25 0.00000 0.00001\n",
"26 0.00000 0.00001\t 27 0.00000 0.00002\n",
"28 0.00000 0.00002\t 29 0.00000 0.00002\n",
"30 0.00000 0.00001\t 31 0.03580 0.03612\n",
"32 0.08447 0.08517\t 33 0.00000 0.00003\n",
"34 0.00000 0.00001\t 35 0.02849 0.02747\n",
"36 0.13489 0.13487\t 37 0.07446 0.07264\n",
"38 0.00000 0.00001\t 39 0.00000 0.00001\n",
"40 0.00000 0.00003\t 41 0.07312 0.07388\n",
"42 0.00000 0.00004\t 43 0.00000 0.00003\n",
"44 0.01336 0.01485\t 45 0.00000 0.00002\n",
"46 0.00000 0.00009\t 47 0.02593 0.02555\n",
"48 0.00000 0.00003\t 49 0.00000 0.00000\n"
]
}
],
Expand Down Expand Up @@ -757,7 +748,7 @@
"# since working with non-trivial size, set a time limit\n",
"time_limit = 60*5 # 5 minutes\n",
"model_std.setParam(GRB.Param.TimeLimit, time_limit)\n",
"model_rbs.setParam(GRB.Param.TimeLimit, time_limit)\n",
"model_std.setParam(GRB.Param.TimeLimit, time_limit)\n",
"\n",
"# for the same reason, also set a duality gap tolerance\n",
"duality_gap = 0.05\n",
Expand All @@ -770,9 +761,9 @@
"\n",
"# HACK code which prints the results for comparison in a nice format\n",
"print(\" i w_std w_rbs \\t\\t i w_std w_rbs\")\n",
"for candidate in range(25):\n",
" print(f\"{candidate:02d} {w_std.X[candidate]:.5f} {w_rbs.X[candidate]:.5f}\\t \\\n",
" {candidate+25:02d} {w_std.X[candidate+25]:.5f} {w_rbs.X[candidate+25]:.5f}\")"
"for candidate in range(0,25):\n",
" print(f\"{candidate*2:02d} {w_std.X[candidate*2]:.5f} {w_rbs.X[candidate*2]:.5f}\\t \\\n",
" {candidate*2+1:02d} {w_std.X[candidate*2+1]:.5f} {w_rbs.X[candidate*2+1]:.5f}\")"
]
},
{
Expand Down

0 comments on commit 1cd5d31

Please sign in to comment.