-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_quick.py
More file actions
71 lines (55 loc) · 2.11 KB
/
test_quick.py
File metadata and controls
71 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Quick test to verify the materials.py file can be executed.
"""
import sys
import os
def test_import():
"""Test that materials.py can be imported and executed."""
print("Testing materials.py execution...")
# Read and execute the materials file
materials_path = os.path.join("benchmark", "application", "materials.py")
if not os.path.exists(materials_path):
print(f"ERROR: {materials_path} not found")
return False
with open(materials_path, "r", encoding="utf-8") as f:
code = f.read()
# Execute in a clean namespace
exec_globals = {}
try:
exec(code, exec_globals)
print("SUCCESS: materials.py executed successfully")
# Check for required variables
required_vars = ['m', 'x', 'material_quality', 'material_abundance',
'material_usage', 'material_cost']
missing = []
for var in required_vars:
if var not in exec_globals:
missing.append(var)
if missing:
print(f"ERROR: Missing variables: {', '.join(missing)}")
return False
print("SUCCESS: All required variables found")
# Check model status
model = exec_globals['m']
if hasattr(model, 'status'):
if model.status == 2: # GRB.OPTIMAL
print(f"SUCCESS: Model solved to optimality (cost: {model.objVal:.4f})")
else:
print(f"WARNING: Model status: {model.status} (not optimal)")
return True
except ImportError as e:
if 'gurobipy' in str(e):
print("ERROR: Gurobi not installed. Please install gurobipy:")
print(" pip install gurobipy")
print(" (Also requires Gurobi Optimizer license)")
else:
print(f"ERROR: Import error: {e}")
return False
except Exception as e:
print(f"ERROR: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
success = test_import()
sys.exit(0 if success else 1)