From 574aa7dcc378d958b31a04d99d3e63f410a5865d Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Wed, 8 Dec 2021 10:17:18 +1100 Subject: [PATCH] Add initial DLMO model and converted data --- dlmo.mzn | 65 ++++++++++++++++++ full.dzn | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++ output.txt | 91 +++++++++++++++++++++++++ 3 files changed, 346 insertions(+) create mode 100644 dlmo.mzn create mode 100644 full.dzn create mode 100644 output.txt diff --git a/dlmo.mzn b/dlmo.mzn new file mode 100644 index 0000000..ae3a685 --- /dev/null +++ b/dlmo.mzn @@ -0,0 +1,65 @@ +% --- Data quantities --- +enum Patient; % Patients for which samples have been taken +set of int: Horizon = -5..2; % (Relative) sampling times + +% --- Data input --- +float: DLMO_threshold = 13.043; +array[Patient, Horizon] of float: sample; + +% --- Derived data --- + +% For each patient: after which sample could we stop and have found dlmo? (occasion must then include `critical_test[PT]` and its successor to catch it). +array[Patient] of var Horizon: critical_sample = [ min([i | i in -5..1 where sample[pt, i] <= DLMO_threshold /\ sample[pt, i+1] >= DLMO_threshold]) | pt in Patient]; + +% --- Decisions --- +% First occasion: +var Horizon: first_sample; % When to start sampling on the first occasion +var 1..length(Horizon)-1: first_num_samples; % How many samples to take on the first occasion + +% Second occasion: +var 1..length(Horizon)-1: second_num_samples; % How many samples to take on the second occasion + +% (Assumption: If the levels were to high in all samples during the first occasion, then we sample `second_num_samples` ending with the `first_sample`. +% If the levels were to low in all samples during the first occasion, then we sample `second_num_samples` from `first_sample + first_num_samples`.) + +% --- Decision Consequences --- + +% For each patient: will their DLMO be detected on the first occasion? +array[Patient] of var bool: first_detected = [ + critical_sample[pt] >= first_sample /\ critical_sample[pt] + 1 <= first_sample + (first_num_samples - 1) + | pt in Patient +]; + +% --- Constraint --- + +% The DLMO should be detected on the second occasion (if not detected on the first occasion) +constraint forall (pt in Patient) ( + first_detected[pt] + % Before first occasion + \/ (critical_sample[pt] >= first_sample - (second_num_samples - 1) /\ critical_sample[pt] + 1 <= first_sample) + % After first occasion + \/ (critical_sample[pt] >= first_sample + (first_num_samples - 1) /\ critical_sample[pt] + 1 <= first_sample + (first_num_samples - 1) + (second_num_samples - 1)) +); + +% --- Objective --- +solve minimize + % Number of tests on first occasion + (length(Patient) * first_num_samples) + % Number of test on second occasion + + (count(pt in Patient) (not first_detected[pt]) * second_num_samples); + +% --- Output --- + +output ["First Occasion:\n"] +++ [format(2, i) ++ " " | i in Horizon] ++ ["\n |"] +++ [if i in fix(first_sample)..fix(first_sample + (first_num_samples-1) - 1) then "====|" else "----|" endif | i in -5..1] +++ ["\n\nFirst try (%): \(count(first_detected) / length(Patient) * 100)\n"] +++ ["\n\nSecond Occasion:\n"] +++ [format(2, i) ++ " " | i in Horizon] ++ ["\n |"] +++ [if i in fix(first_sample-(second_num_samples-1))..fix(first_sample-1) \/ i in fix(first_sample + (first_num_samples - 1))..fix(first_sample + (first_num_samples - 1) + (second_num_samples - 1) - 1) then "====|" else "----|" endif | i in -5..1] +++ ["\n\nTotal number of tests = \(_objective);"] + + +++ ["\n\n\nfirst_sample = \(first_sample);\n"] +++ ["first_num_samples = \(first_num_samples);\n"] +++ ["second_num_samples = \(second_num_samples);"]; diff --git a/full.dzn b/full.dzn new file mode 100644 index 0000000..d506ce6 --- /dev/null +++ b/full.dzn @@ -0,0 +1,190 @@ +% Note: we currently do not consider the patients for which no DLMO can be determined +% (in any model they would currently add a fixed cost) +Patient = PT(1..182); + +sample = array2d(Patient, Horizon, [|4.97, 5.19, 4.84, 12.12, 44.09, 76.90, 77.93, 86.89| +0.00, 0.00, 0.00, 6.50, 34.29, 47.99, 50.50, 79.16| +0.00, 9.39, 7.50, 23.42, 28.23, 38.96, 40.67, 44.68| +0.00, 0.00, 0.00, 6.44, 35.58, 39.08, 77.71, 76.78| +0.00, 7.85, 18.19, 33.64, 42.33, 57.58, 58.56, 72.36| +0.00, 6.56, 28.72, 55.35, 81.48, 90.26, 114.08, 110.23| +4.54, 5.09, 5.57, 35.97, 55.70, 99.52, 105.59, 130.38| +5.37, 0.00, 6.58, 6.99, 8.19, 18.11, 32.69, 44.02| +0.00, 0.00, 0.00, 0.00, 47.95, 60.65, 59.75, 90.52| +5.13, 4.29, 14.02, 49.11, 74.69, 105.65, 118.19, 103.78| +0.00, 0.00, 0.00, 4.41, 22.73, 36.32, 42.12, 28.73| +6.87, 6.16, 5.89, 7.78, 19.12, 64.71, 102.07, 97.34| +0.00, 6.02, 0.00, 6.23, 11.57, 35.20, 94.44, 120.66| +8.12, 6.65, 9.37, 12.83, 17.46, 72.01, 42.14, 54.59| +0.00, 0.00, 0.00, 7.46, 30.10, 46.28, 52.28, 59.77| +0.00, 4.59, 25.89, 75.61, 105.39, 141.76, 177.26, 159.12| +14.96, 7.77, 5.51, 39.53, 108.90, 80.21, 140.08, 98.11| +0.00, 0.00, 4.55, 10.25, 28.39, 46.41, 51.09, 49.02| +4.82, 8.89, 10.15, 26.82, 28.01, 40.84, 39.39, 42.80| +0.00, 0.00, 0.00, 0.00, 8.89, 30.70, 43.51, 59.28| +10.88, 8.88, 14.69, 56.99, 86.15, 104.51, 55.64, 110.84| +7.81, 8.36, 11.69, 46.93, 105.81, 129.98, 120.09, 116.77| +4.40, 0.00, 0.00, 0.00, 43.20, 73.60, 87.40, 91.40| +10.68, 10.79, 18.36, 27.50, 45.50, 51.97, 55.66, 30.57| +0.00, 5.95, 6.15, 26.40, 62.07, 75.43, 87.14, 83.09| +0.00, 0.00, 4.47, 20.93, 46.91, 64.55, 61.22, 83.95| +5.63, 5.49, 11.11, 22.32, 34.06, 84.91, 94.01, 108.89| +4.67, 4.87, 99.00, 20.55, 133.68, 98.20, 98.27, 99.00| +6.01, 4.92, 0.00, 9.90, 37.57, 58.72, 203.30, 78.84| +5.03, 5.20, 20.34, 61.96, 80.45, 37.42, 96.46, 118.70| +4.87, 26.81, 61.75, 63.61, 41.87, 85.16, 57.65, 62.28| +13.48, 12.89, 81.21, 121.83, 150.09, 126.28, 192.29, 173.41| +% 6.30, 4.90, 4.90, 4.40, 0.00, 5.30, 12.50, 12.30| +0.00, 0.00, 29.20, 80.60, 107.60, 136.10, 162.70, 134.90| +5.09, 18.19, 44.45, 53.86, 87.03, 87.61, 92.43, 71.11| +0.00, 6.50, 10.70, 11.40, 39.00, 42.10, 43.10, 22.60| +0.00, 4.98, 15.59, 51.45, 110.54, 92.19, 99.66, 106.87| +0.00, 0.00, 0.00, 4.50, 21.54, 42.38, 52.73, 53.80| +0.00, 0.00, 28.85, 81.47, 119.08, 143.88, 168.47, 151.34| +7.40, 10.50, 13.70, 10.30, 44.50, 74.70, 80.60, 96.30| +0.00, 0.00, 18.96, 53.70, 100.30, 98.26, 99.79, 105.86| +0.00, 0.00, 0.00, 17.90, 39.90, 44.60, 64.20, 83.60| +0.00, 0.00, 25.38, 52.60, 76.69, 89.95, 77.72, 83.67| +4.30, 4.30, 4.36, 5.47, 16.96, 36.32, 45.99, 42.82| +0.00, 4.40, 10.00, 39.10, 42.90, 45.60, 30.40, 62.00| +4.40, 0.00, 4.50, 6.70, 41.60, 89.30, 113.30, 117.10| +0.00, 0.00, 0.00, 9.10, 29.00, 53.10, 48.60, 94.10| +0.00, 0.00, 0.00, 12.30, 42.40, 59.40, 73.20, 85.70| +0.00, 4.90, 0.00, 5.30, 28.30, 45.20, 55.80, 88.50| +4.60, 31.39, 70.46, 84.31, 105.12, 116.62, 98.98, 116.68| +0.00, 0.00, 0.00, 8.15, 49.21, 95.04, 123.12, 127.27| +0.00, 0.00, 0.00, 0.00, 0.00, 4.53, 21.93, 36.53| +4.80, 0.00, 0.00, 5.50, 17.40, 42.80, 36.50, 30.20| +4.83, 0.00, 0.00, 21.46, 62.93, 98.07, 104.25, 123.67| +0.00, 0.00, 4.70, 7.67, 14.25, 21.76, 20.83, 20.28| +0.00, 4.44, 9.55, 29.27, 85.78, 126.10, 159.90, 181.05| +0.00, 0.00, 0.00, 31.97, 61.88, 89.17, 84.67, 80.79| +0.00, 0.00, 12.46, 43.99, 58.51, 85.83, 103.51, 87.77| +0.00, 0.00, 28.46, 46.76, 50.49, 70.97, 53.20, 71.15| +4.61, 6.52, 59.50, 79.97, 103.44, 100.75, 124.88, 119.70| +0.00, 5.36, 44.07, 62.02, 62.25, 79.68, 95.32, 80.29| +0.00, 0.00, 10.69, 12.83, 17.66, 22.74, 27.42, 31.27| +0.00, 0.00, 4.80, 28.05, 50.94, 64.22, 54.55, 37.87| +4.30, 4.31, 5.05, 9.28, 42.51, 77.53, 79.92, 102.79| +0.00, 0.00, 0.00, 10.02, 93.17, 127.61, 213.48, 224.09| +0.00, 0.00, 17.40, 46.30, 72.05, 68.78, 65.22, 67.88| +4.30, 4.30, 4.80, 32.87, 84.36, 93.10, 109.63, 124.86| +5.39, 4.44, 4.41, 0.00, 7.50, 45.71, 79.67, 98.26| +17.00, 4.69, 5.08, 4.70, 17.75, 42.70, 55.89, 63.86| +0.00, 0.00, 47.00, 18.17, 29.36, 36.30, 49.55, 60.52| +0.00, 6.01, 0.00, 11.20, 30.93, 49.27, 52.18, 60.08| +0.00, 0.00, 0.00, 0.00, 0.00, 11.30, 22.88, 36.02| +0.00, 22.00, 15.54, 99.68, 117.18, 313.40, 119.80, 153.18| +0.00, 5.87, 10.40, 16.65, 21.37, 23.79, 24.27, 28.56| +0.00, 0.00, 8.80, 28.92, 43.46, 54.51, 48.92, 49.44| +0.00, 0.00, 0.00, 0.00, 15.62, 30.74, 42.84, 44.99| +0.00, 0.00, 0.00, 7.78, 31.20, 46.08, 56.69, 75.77| +0.00, 12.56, 30.28, 45.89, 57.34, 75.90, 59.86, 60.32| +4.30, 4.30, 4.64, 20.71, 34.36, 44.93, 47.62, 40.02| +2.93, 2.74, 8.88, 51.92, 133.76, 139.63, 170.27, 167.76| +5.71, 4.30, 4.30, 4.32, 16.28, 86.81, 101.54, 126.13| +0.00, 0.00, 0.00, 0.00, 4.77, 20.42, 42.98, 43.51| +0.00, 0.00, 7.18, 41.17, 57.24, 65.86, 80.03, 73.89| +0.00, 22.38, 50.23, 71.09, 77.91, 85.20, 149.13, 91.72| +% 22.97, 47.85, 73.19, 64.78, 62.53, 76.47, 61.64, 51.15| +0.00, 0.00, 0.00, 27.74, 63.32, 79.23, 86.92, 64.19| +0.00, 0.00, 0.00, 20.93, 60.17, 69.74, 47.88, 57.97| +5.26, 16.03, 22.16, 33.62, 37.46, 23.13, 31.81, 49.78| +0.00, 0.00, 0.00, 13.63, 40.36, 47.44, 80.64, 45.01| +4.30, 4.30, 4.30, 4.35, 43.90, 118.68, 102.05, 200.41| +0.00, 0.00, 0.00, 5.82, 17.74, 42.03, 50.00, 45.82| +10.98, 37.05, 63.98, 91.31, 123.08, 102.46, 90.99, 96.30| +5.96, 5.26, 5.20, 20.67, 38.00, 73.44, 125.74, 175.59| +1.67, 1.88, 0.00, 28.31, 60.58, 85.03, 108.97, 117.34| +1.34, 0.00, 14.67, 16.42, 20.36, 26.76, 30.29, 33.76| +4.54, 2.56, 2.37, 0.00, 29.86, 84.49, 97.76, 149.29| +4.35, 4.86, 5.80, 23.29, 44.28, 60.99, 71.09, 76.39| +0.00, 0.00, 0.00, 0.00, 0.00, 5.28, 21.22, 34.09| +4.82, 0.00, 0.00, 0.00, 14.63, 79.94, 164.28, 168.67| +5.02, 5.12, 7.46, 7.40, 27.09, 80.03, 123.93, 166.03| +0.00, 0.00, 0.00, 22.70, 86.12, 132.42, 139.95, 137.92| +12.05, 11.24, 23.41, 72.70, 149.83, 200.04, 202.82, 162.09| +0.00, 0.00, 0.00, 0.00, 5.29, 9.05, 23.84, 37.83| +0.00, 0.00, 0.00, 0.00, 23.52, 46.50, 93.15, 114.94| +0.00, 0.00, 0.00, 0.00, 8.26, 27.27, 33.72, 55.11| +0.00, 0.00, 36.84, 82.89, 105.54, 87.70, 91.38, 73.71| +5.61, 4.30, 4.35, 4.30, 5.98, 15.34, 65.71, 109.01| +0.00, 4.42, 0.00, 5.00, 27.55, 63.69, 105.86, 115.72| +0.00, 5.21, 4.49, 12.66, 14.28, 27.04, 39.67, 41.77| +0.00, 0.00, 0.00, 0.00, 12.70, 24.02, 51.70, 59.93| +0.00, 6.45, 5.56, 8.60, 30.76, 49.76, 56.23, 63.79| +4.30, 4.30, 5.08, 26.72, 65.11, 77.24, 92.57, 104.37| +4.51, 53.83, 92.20, 112.56, 130.80, 113.71, 139.85, 143.99| +6.24, 5.17, 8.25, 14.92, 48.79, 57.21, 38.88, 227.42| +7.70, 22.71, 23.02, 25.76, 28.13, 31.16, 16.49, 21.28| +6.40, 4.30, 4.35, 11.27, 53.57, 93.47, 124.54, 133.82| +4.30, 4.30, 4.30, 4.30, 4.34, 60.84, 60.84, 33.47| +0.00, 17.71, 31.52, 46.63, 51.47, 54.59, 61.72, 52.48| +0.00, 0.00, 0.00, 0.00, 5.53, 36.20, 57.51, 62.23| +4.72, 5.40, 11.01, 40.27, 55.94, 61.97, 76.10, 43.84| +7.90, 8.05, 38.11, 38.11, 38.11, 38.11, 171.00, 171.00| +0.00, 0.00, 31.89, 73.13, 98.75, 133.02, 121.90, 150.39| +0.00, 6.43, 27.58, 41.73, 59.05, 84.57, 99.09, 97.78| +0.00, 0.00, 0.00, 0.00, 15.88, 47.96, 64.92, 64.76| +0.00, 0.00, 0.00, 0.00, 0.00, 21.35, 87.33, 103.86| +0.00, 0.00, 4.58, 15.75, 16.36, 31.11, 33.61, 35.94| +1.19, 8.17, 24.66, 44.71, 56.07, 63.69, 48.67, 54.29| +0.00, 0.00, 41.38, 67.70, 125.74, 138.76, 123.50, 133.17| +7.92, 10.80, 5.60, 12.81, 83.96, 153.38, 156.40, 170.01| +0.00, 0.00, 41.94, 94.82, 117.98, 148.65, 154.05, 149.55| +0.00, 0.00, 0.00, 0.00, 5.16, 41.94, 80.96, 111.44| +0.00, 0.00, 18.91, 30.59, 43.55, 38.02, 33.15, 33.05| +0.00, 0.00, 0.00, 7.23, 37.02, 69.36, 71.25, 79.08| +0.00, 0.00, 26.16, 50.96, 85.26, 139.04, 110.83, 108.32| +20.32, 4.30, 4.50, 19.75, 35.82, 39.73, 71.45, 91.00| +4.63, 4.42, 0.00, 0.00, 6.58, 51.11, 86.67, 133.05| +3.95, 5.46, 4.75, 11.99, 20.46, 29.34, 40.43, 56.02| +0.00, 0.00, 0.00, 17.50, 35.50, 44.50, 46.60, 54.10| +4.63, 0.00, 11.68, 60.55, 84.95, 113.23, 115.49, 110.55| +4.60, 7.09, 48.41, 108.07, 163.77, 145.91, 223.76, 268.54| +10.90, 57.80, 122.30, 221.60, 213.40, 229.60, 181.40, 147.00| +0.00, 4.80, 4.60, 8.60, 27.70, 47.80, 39.50, 38.10| +7.40, 26.10, 39.20, 26.80, 39.30, 64.10, 62.30, 45.30| +4.80, 0.00, 11.20, 33.20, 65.10, 84.70, 100.80, 107.60| +0.00, 0.00, 0.00, 0.00, 21.00, 40.80, 49.80, 70.90| +5.20, 27.50, 55.40, 55.80, 58.90, 46.60, 54.20, 61.60| +6.30, 0.00, 4.80, 6.10, 25.80, 42.70, 58.40, 70.20| +4.30, 4.30, 14.40, 21.03, 30.10, 36.41, 33.18, 34.39| +0.00, 0.00, 32.80, 77.20, 127.60, 129.90, 164.40, 134.10| +0.00, 0.00, 0.00, 0.00, 0.00, 12.00, 20.20, 28.10| +0.00, 0.00, 0.00, 0.00, 0.00, 5.21, 51.61, 60.09| +0.00, 0.00, 0.00, 9.50, 21.80, 32.00, 38.50, 43.10| +0.00, 0.00, 0.00, 26.50, 40.00, 77.80, 96.40, 111.20| +0.00, 11.00, 22.90, 32.90, 41.70, 31.90, 30.00, 30.60| +0.00, 9.90, 36.80, 54.80, 55.00, 63.10, 55.00, 57.00| +0.00, 0.00, 18.33, 69.24, 127.84, 160.72, 158.61, 149.17| +0.00, 0.00, 22.82, 48.72, 79.89, 90.70, 70.58, 50.38| +0.00, 0.00, 5.68, 30.92, 56.18, 72.43, 66.86, 63.57| +4.30, 4.30, 5.40, 14.36, 29.36, 24.36, 28.49, 39.21| +0.00, 0.00, 0.00, 0.00, 11.21, 26.14, 41.31, 52.55| +% 36.02, 48.56, 53.76, 51.87, 52.43, 56.25, 45.98, 46.82| +0.00, 0.00, 0.00, 0.00, 0.00, 5.37, 26.35, 38.29| +0.00, 32.51, 48.57, 81.69, 135.84, 106.51, 101.68, 80.68| +4.30, 4.30, 4.30, 24.39, 74.00, 135.56, 162.35, 189.05| +0.00, 0.00, 12.16, 33.68, 47.06, 52.28, 51.30, 60.57| +7.02, 26.42, 49.18, 56.19, 58.87, 58.80, 59.25, 46.18| +0.00, 0.00, 0.00, 4.64, 33.94, 50.50, 70.55, 85.56| +0.00, 0.00, 15.04, 83.92, 59.60, 69.90, 71.35, 136.81| +0.00, 8.25, 101.73, 49.97, 52.34, 80.84, 66.21, 57.82| +0.00, 0.00, 0.00, 7.74, 48.52, 84.95, 101.25, 125.75| +0.00, 0.00, 0.00, 6.94, 27.47, 30.94, 47.81, 55.85| +1.19, 6.92, 22.94, 34.28, 51.26, 77.97, 102.60, 119.15| +1.57, 1.88, 6.00, 27.42, 50.93, 60.45, 60.32, 59.98| +0.00, 0.00, 0.00, 0.00, 0.00, 5.26, 41.27, 71.66| +0.00, 4.52, 12.09, 61.07, 111.06, 146.78, 156.34, 129.06| +0.00, 37.04, 80.05, 133.99, 162.85, 179.17, 197.68, 289.61| +0.00, 0.00, 10.95, 22.03, 65.03, 101.97, 112.27, 117.39| +0.00, 0.00, 59.66, 134.23, 173.57, 204.06, 184.29, 156.13| +1.00, 0.98, 2.04, 8.83, 25.97, 39.06, 51.50, 64.34| +% 16.39, 64.71, 99.83, 113.69, 133.73, 137.84, 124.19, 113.60| +0.00, 0.00, 0.00, 0.00, 0.00, 25.01, 49.04, 84.47| +0.00, 0.00, 5.47, 40.55, 91.17, 153.73, 161.62, 138.69| +0.00, 0.00, 0.00, 0.00, 65.94, 47.36, 62.11, 65.17| +0.00, 4.42, 0.00, 6.04, 20.05, 34.11, 48.37, 52.13| +0.00, 0.00, 5.46, 41.75, 97.94, 102.38, 118.73, 109.30| +0.00, 0.00, 4.58, 52.37, 55.64, 58.75, 86.94, 68.68|]); diff --git a/output.txt b/output.txt new file mode 100644 index 0000000..ad85e28 --- /dev/null +++ b/output.txt @@ -0,0 +1,91 @@ +First Occasion: +-5 -4 -3 -2 -1 0 1 2 + |----|----|----|====|====|====|----| + +First try (%): 41.75824175824176 + + +Second Occasion: +-5 -4 -3 -2 -1 0 1 2 + |====|====|====|----|----|----|====| + +Total number of tests = 1470; + + +first_sample = -2; +first_num_samples = 4; +second_num_samples = 7; +---------- +First Occasion: +-5 -4 -3 -2 -1 0 1 2 + |----|----|----|====|----|----|----| + +First try (%): 29.12087912087912 + + +Second Occasion: +-5 -4 -3 -2 -1 0 1 2 + |====|====|====|----|====|====|====| + +Total number of tests = 1009; + + +first_sample = -2; +first_num_samples = 2; +second_num_samples = 5; +---------- +First Occasion: +-5 -4 -3 -2 -1 0 1 2 + |----|----|----|====|----|----|----| + +First try (%): 29.12087912087912 + + +Second Occasion: +-5 -4 -3 -2 -1 0 1 2 + |====|====|====|----|====|====|====| + +Total number of tests = 880; + + +first_sample = -2; +first_num_samples = 2; +second_num_samples = 4; +---------- +First Occasion: +-5 -4 -3 -2 -1 0 1 2 + |----|====|====|====|----|----|----| + +First try (%): 78.57142857142857 + + +Second Occasion: +-5 -4 -3 -2 -1 0 1 2 + |====|----|----|----|====|====|----| + +Total number of tests = 845; + + +first_sample = -4; +first_num_samples = 4; +second_num_samples = 3; +---------- +First Occasion: +-5 -4 -3 -2 -1 0 1 2 + |----|----|====|====|----|----|----| + +First try (%): 54.94505494505495 + + +Second Occasion: +-5 -4 -3 -2 -1 0 1 2 + |====|====|----|----|====|====|----| + +Total number of tests = 792; + + +first_sample = -3; +first_num_samples = 3; +second_num_samples = 3; +---------- +==========