mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-10 11:28:51 -06:00
Add _gurobipy suffix to all build_model functions
This commit is contained in:
@@ -87,8 +87,10 @@
|
||||
"\n",
|
||||
"# Set up Python logging\n",
|
||||
"import logging\n",
|
||||
"\n",
|
||||
"logging.basicConfig(level=logging.WARNING)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def build_tsp_model_gurobipy_simplified(data):\n",
|
||||
" # Read data from file if a filename is provided\n",
|
||||
" if isinstance(data, str):\n",
|
||||
@@ -99,9 +101,7 @@
|
||||
"\n",
|
||||
" # Create set of edges between every pair of cities, for convenience\n",
|
||||
" edges = tuplelist(\n",
|
||||
" (i, j)\n",
|
||||
" for i in range(data.n_cities)\n",
|
||||
" for j in range(i + 1, data.n_cities)\n",
|
||||
" (i, j) for i in range(data.n_cities) for j in range(i + 1, data.n_cities)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Add binary variable x[e] for each edge e\n",
|
||||
@@ -113,11 +113,8 @@
|
||||
" # Add constraint: must choose two edges adjacent to each city\n",
|
||||
" model.addConstrs(\n",
|
||||
" (\n",
|
||||
" quicksum(\n",
|
||||
" x[min(i, j), max(i, j)]\n",
|
||||
" for j in range(data.n_cities)\n",
|
||||
" if i != j\n",
|
||||
" ) == 2\n",
|
||||
" quicksum(x[min(i, j), max(i, j)] for j in range(data.n_cities) if i != j)\n",
|
||||
" == 2\n",
|
||||
" for i in range(data.n_cities)\n",
|
||||
" ),\n",
|
||||
" name=\"eq_degree\",\n",
|
||||
@@ -129,7 +126,7 @@
|
||||
" \"\"\"\n",
|
||||
" # Query current value of the x variables\n",
|
||||
" x_val = m.inner.cbGetSolution(x)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # Initialize empty set of violations\n",
|
||||
" violations = []\n",
|
||||
"\n",
|
||||
@@ -164,9 +161,7 @@
|
||||
" \"\"\"\n",
|
||||
" print(f\"Enforcing {len(violations)} subtour elimination constraints\")\n",
|
||||
" for violation in violations:\n",
|
||||
" m.add_constr(\n",
|
||||
" quicksum(x[e[0], e[1]] for e in violation) >= 2\n",
|
||||
" )\n",
|
||||
" m.add_constr(quicksum(x[e[0], e[1]] for e in violation) >= 2)\n",
|
||||
"\n",
|
||||
" return GurobiModel(\n",
|
||||
" model,\n",
|
||||
@@ -494,7 +489,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"solver = LearningSolver(components=[]) # empty set of ML components\n",
|
||||
"solver = LearningSolver(components=[]) # empty set of ML components\n",
|
||||
"solver.optimize(test_data[0], build_tsp_model_gurobipy_simplified);"
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user