Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
dlmo-model dlmo.mzn
3.7 kB · 83 lines
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384% --- Data quantities ---enum Patient; % Patients for which samples have been takenset of int: Horizon = -5..2; % (Relative) sampling times% --- Data input ---float: DLMO_threshold = 13.043;array[Patient] of opt float: dlmo;array[Patient, Horizon] of opt float: sample;% consistency in terms of STDEVarray[Patient] of opt float: consistency;test has_dlmo(Patient: pt) = occurs(dlmo[pt]);% --- Derived data ---% For each patient: after which sample could we stop and have found dlmo? (test timeframe must then include `critical_test[PT]` and its successor to catch it).array[Patient] of Horizon: critical_sample = [ if has_dlmo(pt) then min([i | i in -5..1 where sample[pt, i] <= DLMO_threshold /\ sample[pt, i+1] >= DLMO_threshold]) else min(Horizon) endif| pt in Patient];% --- Decisions ---% First test:var Horizon: first_sample; % When to start sampling on the first test var 2..length(Horizon): num_samples; % How many samples to take on the first test % (Assumption: If the levels were to high in all samples during the first test, then we sample `num_samples` ending with the `first_sample`.% If the levels were to low in all samples during the first test, then we sample `num_samples` from `first_sample + num_samples`.)% --- Decision Consequences ---% For each patient: will their DLMO be detected on the first test?array[Patient] of var bool: first_detected = [ has_dlmo(pt) /\ (critical_sample[pt] >= first_sample /\ critical_sample[pt] + 1 <= first_sample + (num_samples - 1)) | pt in Patient];int: num_before ::output_only :: output = sum([critical_sample[pt] < fix(first_sample) | pt in Patient where has_dlmo(pt)]);int: num_after ::output_only :: output = sum([critical_sample[pt] >= fix(first_sample) + (fix(num_samples) - 1) | pt in Patient where has_dlmo(pt)]);% For each patient: will their DLMO be detected on the first test?% --- Constraint ---% The DLMO should be detected during the second test (if not detected in the first test)constraint forall (pt in Patient where has_dlmo(pt)) ( first_detected[pt] % Before first \/ (critical_sample[pt] >= first_sample - (num_samples - 1) /\ critical_sample[pt] + 1 <= first_sample) % After first test time window \/ (critical_sample[pt] >= first_sample + (num_samples - 1) /\ critical_sample[pt] + 1 <= first_sample + (num_samples - 1) + (num_samples - 1)));% --- Objective ---% solve minimize total_tests;% Pareto Front objectivesvar int: total_samples ::output = % Number of samples on first test (length([pt | pt in Patient where has_dlmo(pt)]) * num_samples) % Number of samples on second test + (count(pt in Patient where has_dlmo(pt)) (not first_detected[pt]) * num_samples);var int: total_not_detected ::output = length([pt | pt in Patient where has_dlmo(pt)]) - count(first_detected);var int: num_patients ::output = length([pt | pt in Patient where has_dlmo(pt)]);% --- Output ---output ["First Round:\n"]++ [format(2, i) ++ " " | i in Horizon] ++ ["\n |"]++ [if i in fix(first_sample)..fix(first_sample + (num_samples-1) - 1) then "====|" else "----|" endif | i in -5..1]++ ["\n\nFirst try (%): \(count(first_detected) / length([pt | pt in Patient where has_dlmo(pt)]) * 100)\n"]++ ["\n\nSecond Round:\n"]++ [format(2, i) ++ " " | i in Horizon] ++ ["\n |"]++ [if i in fix(first_sample-(num_samples-1))..fix(first_sample-1) \/ i in fix(first_sample + (num_samples - 1))..fix(first_sample + (num_samples - 1) + (num_samples - 1) - 1) then "====|" else "----|" endif | i in -5..1]++ ["\n\nTotal number of tests = \(total_samples);"]++ ["\n\n\nfirst_sample = \(first_sample);\n"]++ ["num_samples = \(num_samples);\n"]