dsfdfw

Untitled

Mar 18th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.93 KB | None | 0 0
  1. {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 0.91, (1, 14): 0.8200000000000001, (2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 0.91, (2, 10): 0.91, (2, 11): 0.91, (2, 12): 0.91, (2, 13): 0.8200000000000001, (2, 14): 0.8200000000000001, (3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 1.0, (3, 14): 1.0, (4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 1.0, (4, 14): 1.0}
  2. {'Physician_1': [{(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 0.91, (1, 10): 0.91, (1, 11): 0.91, (1, 12): 0.91, (1, 13): 0.8200000000000001, (1, 14): 0.8200000000000001}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 1.0, (1, 14): 1.0}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 1.0, (1, 14): 1.0}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 1.0, (1, 14): 1.0}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 1.0, (1, 14): 1.0}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 1.0, (1, 14): 1.0}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 0.91, (1, 13): 0.91, (1, 14): 0.91}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 1.0, (1, 14): 1.0}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 0.91, (1, 14): 0.91}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 0.91, (1, 10): 0.91, (1, 11): 0.91, (1, 12): 0.91, (1, 13): 0.91, (1, 14): 0.91}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 0.91, (1, 13): 0.91, (1, 14): 0.91}, {(1, 1): 1.0, (1, 2): 1.0, (1, 3): 1.0, (1, 4): 1.0, (1, 5): 1.0, (1, 6): 1.0, (1, 7): 1.0, (1, 8): 1.0, (1, 9): 1.0, (1, 10): 1.0, (1, 11): 1.0, (1, 12): 1.0, (1, 13): 0.91, (1, 14): 0.91}], 'Physician_2': [{(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 0.91, (2, 10): 0.91, (2, 11): 0.91, (2, 12): 0.91, (2, 13): 0.8200000000000001, (2, 14): 0.8200000000000001}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 1.0, (2, 14): 1.0}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 1.0, (2, 14): 1.0}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 1.0, (2, 14): 1.0}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 1.0, (2, 14): 1.0}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 1.0, (2, 14): 1.0}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 0.91, (2, 13): 0.91, (2, 14): 0.91}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 1.0, (2, 14): 1.0}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 0.91, (2, 14): 0.91}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 0.91, (2, 10): 0.91, (2, 11): 0.91, (2, 12): 0.91, (2, 13): 0.91, (2, 14): 0.91}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 0.91, (2, 13): 0.91, (2, 14): 0.91}, {(2, 1): 1.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 1.0, (2, 5): 1.0, (2, 6): 1.0, (2, 7): 1.0, (2, 8): 1.0, (2, 9): 1.0, (2, 10): 1.0, (2, 11): 1.0, (2, 12): 1.0, (2, 13): 0.91, (2, 14): 0.91}], 'Physician_3': [{(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 0.91, (3, 10): 0.91, (3, 11): 0.91, (3, 12): 0.91, (3, 13): 0.8200000000000001, (3, 14): 0.8200000000000001}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 1.0, (3, 14): 1.0}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 1.0, (3, 14): 1.0}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 1.0, (3, 14): 1.0}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 1.0, (3, 14): 1.0}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 1.0, (3, 14): 1.0}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 0.91, (3, 13): 0.91, (3, 14): 0.91}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 1.0, (3, 14): 1.0}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 0.91, (3, 14): 0.91}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 0.91, (3, 10): 0.91, (3, 11): 0.91, (3, 12): 0.91, (3, 13): 0.91, (3, 14): 0.91}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 0.91, (3, 13): 0.91, (3, 14): 0.91}, {(3, 1): 1.0, (3, 2): 1.0, (3, 3): 1.0, (3, 4): 1.0, (3, 5): 1.0, (3, 6): 1.0, (3, 7): 1.0, (3, 8): 1.0, (3, 9): 1.0, (3, 10): 1.0, (3, 11): 1.0, (3, 12): 1.0, (3, 13): 0.91, (3, 14): 0.91}], 'Physician_4': [{(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 0.91, (4, 10): 0.91, (4, 11): 0.91, (4, 12): 0.91, (4, 13): 0.8200000000000001, (4, 14): 0.8200000000000001}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 1.0, (4, 14): 1.0}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 1.0, (4, 14): 1.0}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 1.0, (4, 14): 1.0}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 1.0, (4, 14): 1.0}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 1.0, (4, 14): 1.0}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 0.91, (4, 13): 0.91, (4, 14): 0.91}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 1.0, (4, 14): 1.0}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 0.91, (4, 14): 0.91}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 0.91, (4, 10): 0.91, (4, 11): 0.91, (4, 12): 0.91, (4, 13): 0.91, (4, 14): 0.91}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 0.91, (4, 13): 0.91, (4, 14): 0.91}, {(4, 1): 1.0, (4, 2): 1.0, (4, 3): 1.0, (4, 4): 1.0, (4, 5): 1.0, (4, 6): 1.0, (4, 7): 1.0, (4, 8): 1.0, (4, 9): 1.0, (4, 10): 1.0, (4, 11): 1.0, (4, 12): 1.0, (4, 13): 0.91, (4, 14): 0.91}]}
  3. {(1, 1): 1.0, (1, 2): 0.0, (1, 3): 0.0, (1, 4): 0.0, (1, 5): 0.0, (1, 6): 0.0, (1, 7): 0.0, (1, 8): 0.0, (1, 9): 0.0, (1, 10): 0.0, (1, 11): 0.0, (1, 12): 0.0, (1, 13): 0.0, (1, 14): 0.0, (1, 15): 0.0, (1, 16): 0.0, (1, 17): 0.0, (1, 18): 0.0, (1, 19): 0.0, (1, 20): 0.0, (1, 21): 0.0, (2, 1): 1.0, (2, 2): 0.0, (2, 3): 0.0, (2, 4): 0.0, (2, 5): 0.0, (2, 6): 0.0, (2, 7): 0.0, (2, 8): 0.0, (2, 9): 0.0, (2, 10): 0.0, (2, 11): 0.0, (2, 12): 0.0, (2, 13): 0.0, (2, 14): 0.0, (2, 15): 0.0, (2, 16): 0.0, (2, 17): 0.0, (2, 18): 0.0, (2, 19): 0.0, (2, 20): 0.0, (2, 21): 0.0, (3, 1): 1.0, (3, 2): 0.0, (3, 3): 0.0, (3, 4): 0.0, (3, 5): 0.0, (3, 6): 0.0, (3, 7): 0.0, (3, 8): 0.0, (3, 9): 0.0, (3, 10): 0.0, (3, 11): 0.0, (3, 12): 0.0, (3, 13): 0.0, (3, 14): 0.0, (3, 15): 0.0, (3, 16): 0.0, (3, 17): 0.0, (3, 18): 0.0, (3, 19): 0.0, (3, 20): 0.0, (3, 21): 0.0, (4, 1): 1.0, (4, 2): 0.0, (4, 3): 0.0, (4, 4): 0.0, (4, 5): 0.0, (4, 6): 0.0, (4, 7): 0.0, (4, 8): 0.0, (4, 9): 0.0, (4, 10): 0.0, (4, 11): 0.0, (4, 12): 0.0, (4, 13): 0.0, (4, 14): 0.0, (4, 15): 0.0, (4, 16): 0.0, (4, 17): 0.0, (4, 18): 0.0, (4, 19): 0.0, (4, 20): 0.0, (4, 21): 0.0}
  4. [1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
  5.  
  6. P
  7.  
  8.  
  9. import pandas as pd
  10. import numpy as np
  11. import time
  12. import matplotlib.pyplot as plt
  13. from masterproblem import *
  14. from plots import *
  15. import seaborn as sns
  16. from gcutil import *
  17. import random
  18. from subproblem import *
  19. from compactsolver import *
  20.  
  21. # Set of indices
  22. I, T, K = [1, 2, 3, 4], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [1, 2, 3]
  23.  
  24. # Create Dataframes
  25. data = pd.DataFrame({
  26. 'I': I + [np.nan] * (max(len(I), len(T), len(K)) - len(I)),
  27. 'T': T + [np.nan] * (max(len(I), len(T), len(K)) - len(T)),
  28. 'K': K + [np.nan] * (max(len(I), len(T), len(K)) - len(K))
  29. })
  30.  
  31. # Additional Sets
  32. Min_WD_i = [2, 3, 2, 3]
  33. Max_WD_i = [5, 5, 5, 6]
  34. S_T = {1: 8, 2: 8, 3: 8}
  35. I_T = {1: 40, 2: 40, 3: 40, 4: 40}
  36. W_I = {1: 1, 2: 1, 3: 1, 4: 1}
  37.  
  38. # Zipping
  39. Min_WD_i = {a: f for a, f in zip(I, Min_WD_i)}
  40. Max_WD_i = {a: g for a, g in zip(I, Max_WD_i)}
  41.  
  42. # Demand Dict
  43. demand_dict1 = {(1, 1): 2, (1, 2): 1, (1, 3): 0, (2, 1): 1, (2, 2): 2, (2, 3): 0, (3, 1): 1, (3, 2): 1, (3, 3): 1, (4, 1): 1, (4, 2): 2, (4, 3): 0,
  44. (5, 1): 2, (5, 2): 0, (5, 3): 1, (6, 1): 1, (6, 2): 1, (6, 3): 1, (7, 1): 0, (7, 2): 3, (7, 3): 0, (8, 1): 2, (8, 2): 1, (8, 3): 0,
  45. (9, 1): 0, (9, 2): 3, (9, 3): 0, (10, 1): 1, (10, 2): 1, (10, 3): 1, (11, 1): 3, (11, 2): 0, (11, 3): 0, (12, 1): 0, (12, 2): 2, (12, 3): 1,
  46. (13, 1): 1, (13, 2): 1, (13, 3): 1, (14, 1): 2, (14, 2): 1, (14, 3): 0}
  47.  
  48. random.seed(124)
  49. def generate_cost(num_days, phys):
  50. cost = {}
  51. shifts = [1, 2, 3]
  52. for day in range(1, num_days + 1):
  53. num_costs = phys
  54. for shift in shifts[:-1]:
  55. shift_cost = random.randrange(0, num_costs)
  56. cost[(day, shift)] = shift_cost
  57. num_costs -= shift_cost
  58. cost[(day, shifts[-1])] = num_costs
  59. return cost
  60.  
  61. demand_dict = generate_cost(len(T), len(I))
  62.  
  63. # Parameter
  64. time_Limit = 3600
  65. max_itr = 10
  66. output_len = 98
  67. mue = 1e-4
  68. eps = 0.09
  69.  
  70. # **** Compact Solver ****
  71. problem_t0 = time.time()
  72. problem = Problem(data, demand_dict, eps)
  73. problem.buildLinModel()
  74. problem.updateModel()
  75. problem.solveModel()
  76.  
  77. obj_val_problem = round(problem.model.objval, 3)
  78. time_problem = time.time() - problem_t0
  79. vals_prob = problem.get_final_values()
  80. print(obj_val_problem)
  81.  
  82.  
  83. # **** Column Generation ****
  84. # Prerequisites
  85. modelImprovable = True
  86. reached_max_itr = False
  87.  
  88. # Get Starting Solutions
  89. problem_start = Problem(data, demand_dict, eps)
  90. problem_start.buildLinModel()
  91. problem_start.model.Params.MIPFocus = 1
  92. problem_start.model.Params.Heuristics = 1
  93. problem_start.model.Params.NoRelHeurTime = 100
  94. problem_start.model.Params.RINS = 10
  95. problem_start.model.Params.MIPGap = 0.7
  96. problem_start.model.update()
  97. problem_start.model.optimize()
  98. start_values = {}
  99. for i in I:
  100. for t in T:
  101. for s in K:
  102. start_values[(i, t, s)] = problem_start.perf[i ,t, s].x
  103.  
  104. start_values_p = {}
  105. for i in I:
  106. for t in T:
  107. start_values_p[(i, t)] = problem_start.p[i ,t].x
  108.  
  109. while True:
  110. # Initialize iterations
  111. itr = 0
  112. t0 = time.time()
  113. last_itr = 0
  114.  
  115. # Create empty results lists
  116. objValHistSP = []
  117. timeHist = []
  118. objValHistRMP = []
  119. avg_rc_hist = []
  120. avg_sp_time = []
  121. gap_rc_hist = []
  122.  
  123. X_schedules = {}
  124. for index in I:
  125. X_schedules[f"Physician_{index}"] = []
  126.  
  127. Perf_schedules = {}
  128. for index in I:
  129. Perf_schedules[f"Physician_{index}"] = []
  130.  
  131. start_values_dict = {}
  132. for i in I:
  133. start_values_dict[f"Physician_{i}"] = {t: start_values_p[(i, t)] for t in T}
  134.  
  135. print(f"DDDD{start_values_dict}")
  136.  
  137. master = MasterProblem(data, demand_dict, max_itr, itr, last_itr, output_len, start_values)
  138. master.buildModel()
  139. print("*" * (output_len + 2))
  140. print("*{:^{output_len}}*".format("Restricted Master Problem successfully built!", output_len=output_len))
  141. print("*" * (output_len + 2))
  142.  
  143. # Initialize and solve relaxed model
  144. master.setStartSolution()
  145. master.updateModel()
  146. master.solveRelaxModel()
  147.  
  148. # Retrieve dual values
  149. duals_i0 = master.getDuals_i()
  150. duals_ts0 = master.getDuals_ts()
  151.  
  152. # Start time count
  153. t0 = time.time()
  154.  
  155. while (modelImprovable) and itr < max_itr:
  156. # Start
  157. itr += 1
  158.  
  159. # Solve RMP
  160. master.current_iteration = itr + 1
  161. master.solveRelaxModel()
  162. objValHistRMP.append(master.model.objval)
  163.  
  164. # Get Duals
  165. duals_i = master.getDuals_i()
  166. duals_ts = master.getDuals_ts()
  167. print(f"DualsI: {duals_i}")
  168. print(f"DualsTs: {duals_ts}")
  169.  
  170. # Save current optimality gap
  171. gap_rc = round(((round(master.model.objval, 3) - round(obj_val_problem, 3)) / round(master.model.objval, 3)), 3)
  172. gap_rc_hist.append(gap_rc)
  173.  
  174. # Solve SPs
  175. modelImprovable = False
  176. for index in I:
  177. # Build SP
  178. subproblem = Subproblem(duals_i, duals_ts, data, index, itr, eps)
  179. subproblem.buildModel()
  180.  
  181. # Save time to solve SP
  182. sub_t0 = time.time()
  183. subproblem.solveModel(time_Limit)
  184. sub_totaltime = time.time() - sub_t0
  185. timeHist.append(sub_totaltime)
  186.  
  187. # Get optimal values
  188. optx_values = subproblem.getOptX()
  189. X_schedules[f"Physician_{index}"].append(optx_values)
  190. optp_values = subproblem.getOptPerf()
  191. Perf_schedules[f"Physician_{index}"].append(optp_values)
  192.  
  193. # Check if SP is solvable
  194. status = subproblem.getStatus()
  195. if status != 2:
  196. raise Exception("*{:^{output_len}}*".format("Pricing-Problem can not reach optimality!", output_len=output_len))
  197.  
  198. # Save ObjVal History
  199. reducedCost = subproblem.model.objval
  200. objValHistSP.append(reducedCost)
  201.  
  202. # Increase latest used iteration
  203. last_itr = itr + 1
  204.  
  205. # Generate and add columns with reduced cost
  206. if reducedCost < -1e-6:
  207. Schedules = subproblem.getNewSchedule()
  208. master.addColumn(index, itr, Schedules)
  209. master.addLambda(index, itr)
  210. master.updateModel()
  211. modelImprovable = True
  212.  
  213. # Update Model
  214. master.updateModel()
  215.  
  216. # Calculate Metrics
  217. avg_rc = sum(objValHistSP) / len(objValHistSP)
  218. avg_rc_hist.append(avg_rc)
  219. objValHistSP.clear()
  220.  
  221. avg_time = sum(timeHist)/len(timeHist)
  222. avg_sp_time.append(avg_time)
  223. timeHist.clear()
  224.  
  225. print("*{:^{output_len}}*".format(f"End CG iteration {itr}", output_len=output_len))
  226.  
  227. if not modelImprovable:
  228. print("*{:^{output_len}}*".format("", output_len=output_len))
  229. print("*{:^{output_len}}*".format("No more improvable columns found.", output_len=output_len))
  230. print("*{:^{output_len}}*".format("", output_len=output_len))
  231. print("*" * (output_len + 2))
  232.  
  233. break
  234.  
  235. if modelImprovable and itr == max_itr:
  236. print("*{:^{output_len}}*".format("More iterations needed. Increase max_itr and restart the process.",
  237. output_len=output_len))
  238. max_itr *= 2
  239. else:
  240. break
  241.  
  242. # Solve Master Problem with integrality restored
  243. master.finalSolve(time_Limit)
  244.  
  245. # Capture total time and objval
  246. total_time_cg = time.time() - t0
  247. final_obj_cg = master.model.objval
  248.  
  249.  
  250. # Define function
  251. def printResults(itr, total_time, time_problem, obj_val_problem, final_obj_cg, nr):
  252. print("*" * (nr + 2))
  253. print("*{:^{nr}}*".format("***** Results *****", nr=nr))
  254. print("*{:^{nr}}*".format("", nr=nr))
  255. print("*{:^{nr}}*".format("Total Column Generation iterations: " + str(itr), nr=nr))
  256. print("*{:^{nr}}*".format("Total elapsed time: " + str(round((total_time), 4)) + " seconds", nr=nr))
  257. print("*{:^{nr}}*".format("Final Column Generation solution: " + str(round(final_obj_cg, 3)), nr=nr))
  258. print("*{:^{nr}}*".format("", nr=nr))
  259. print("*{:^{nr}}*".format("The optimal solution found by compact solver is: " + str(round(obj_val_problem, 3)), nr=nr))
  260. print("*{:^{nr}}*".format("The optimal solution found by the Column Generation solver is: " + str(round(final_obj_cg, 3)), nr=nr))
  261. gap = round(((round(final_obj_cg, 3)-round(obj_val_problem, 3))/round(final_obj_cg, 1))*100, 3)
  262. gap_str = f"{gap}%"
  263. if round(final_obj_cg, 3)-round(obj_val_problem, 3) == 0:
  264. print("*{:^{nr}}*".format("The Optimality-GAP is " + str(gap_str), nr=nr))
  265. else:
  266. print("*{:^{nr}}*".format("The Optimality-GAP is " + str(gap_str), nr=nr))
  267. print("*{:^{nr}}*".format("Column Generation does not provide the global optimal solution!", nr=nr))
  268. print("*{:^{nr}}*".format("", nr=nr))
  269. print("*{:^{nr}}*".format("Solving Times:", nr=nr))
  270. print("*{:^{nr}}*".format(f"Time Column Generation: {round(total_time, 4)} seconds", nr=nr))
  271. print("*{:^{nr}}*".format(f"Time Compact Solver: {round(time_problem, 4)} seconds", nr=nr))
  272. print("*{:^{nr}}*".format("", nr=nr))
  273. if round((total_time), 4) < time_problem:
  274. print("*{:^{nr}}*".format(
  275. "Column Generation is faster by " + str(round((time_problem - round((total_time), 4)), 3)) + " seconds,", nr=nr))
  276. print("*{:^{nr}}*".format(
  277. "which is " + str(round((time_problem/ round(total_time, 4)), 3)) + "x times faster.", nr=nr))
  278. elif round((total_time), 4) > time_problem:
  279. print("*{:^{nr}}*".format(
  280. "Compact solver is faster by " + str(round((round((total_time), 4) - time_problem), 3)) + " seconds,", nr=nr))
  281. print("*{:^{nr}}*".format(
  282. "which is " + str(round((round(total_time, 4)/ time_problem), 3)) + "x times faster.", nr=nr))
  283. else:
  284. print("*{:^{nr}}*".format("Column Generation and compact solver are equally fast: " + str(time_problem) + " seconds", nr=nr))
  285. print("*" * (nr + 2))
  286.  
  287. printResults(itr, total_time_cg, time_problem, obj_val_problem, final_obj_cg, output_len)
  288.  
  289. def plot_obj_val(objValHistRMP):
  290. sns.set(style='darkgrid')
  291. sns.scatterplot(x=list(range(len(objValHistRMP))), y=objValHistRMP, marker='o')
  292. sns.lineplot(x=list(range(len(objValHistRMP))), y=objValHistRMP)
  293. plt.xlabel('CG Iterations')
  294. plt.xticks(range(0, len(objValHistRMP)))
  295. plt.ylabel('Objective function value')
  296. title = 'Optimal objective value: ' + str(round(objValHistRMP[-1], 2))
  297. plt.title(title)
  298. plt.show()
  299.  
  300. def plot_avg_rc(avg_rc_hist):
  301. sns.set(style='darkgrid')
  302. sns.scatterplot(x=list(range(1, len(avg_rc_hist) + 1)), y=avg_rc_hist, marker='o')
  303. sns.lineplot(x=list(range(1, len(avg_rc_hist) + 1)), y=avg_rc_hist)
  304. plt.xlabel('CG Iterations')
  305. plt.xticks(range(1, len(avg_rc_hist)+1))
  306. plt.ylabel('Reduced Cost')
  307. title = 'Final reduced cost: ' + str(round(avg_rc_hist[-1], 2))
  308. plt.title(title)
  309. plt.show()
  310.  
  311. plot_obj_val(objValHistRMP)
  312. plot_avg_rc(avg_rc_hist)
  313.  
  314. print(start_values_p)
  315. print(Perf_schedules)
  316. print(master.printLambdas())
  317.  
  318. print(get_physician_perf_schedules(X_schedules, master.printLambdas(),I))
  319.  
Advertisement
Add Comment
Please, Sign In to add comment