@RobPratt
At previous thread, OPT model is provided to find the best Treatment/Method for BLOC/DT.
Let the solution have improvement for as many as BLOC/DT, the goal is to maximize the total score [improvement=_tmin_x[treatment/method] is less than _tmin_orig for each BLOC/DT. Score=1 if improvement; -5 if none improvement]. This is Stage I.
Now the second stage is to maximize the total sum of the differences between _tmin_x
and _tmin_orig ONLY from the top solutions from Stage I. THAT MEANs an additional constrain
on the TOTAL SCORE from Stage I >= A THESHOLD.
%let optds=mm_out_x6_x;
data have;
set &optds.;
rename _tmin=method1 _tmin_ew=method2 _tmin_wt_r=method3 _tmin_wt_r2=method4;
run;
title "OPT on &optds.";
proc optmodel;
/* read input data */
set METHODS = 1..4;
set <str,num,num> DATE_BLOCK_TREATMENT;
num _tmin_orig {DATE_BLOCK_TREATMENT};
num outcome {DATE_BLOCK_TREATMENT, METHODS};
read data have into DATE_BLOCK_TREATMENT=[dt bloc condi_id] _tmin_orig
{m in METHODS} <outcome[dt,bloc,condi_id,m]=col('method'||m)>;
set TREATMENTS = setof {<d,b,t> in DATE_BLOCK_TREATMENT} t;
set DATE_BLOCK = setof {<d,b,t> in DATE_BLOCK_TREATMENT} <d,b>;
/* define optimization model */
var SelectTreatment {TREATMENTS} binary;
var SelectMethod {METHODS} binary;
var SelectTreatmentMethod {TREATMENTS, METHODS} binary;
var IsGood {DATE_BLOCK} binary;
/* if IsGood[d,b] = 1 then Score[d,b] = 1 else Score[d,b] = -5 */
impvar Score {<d,b> in DATE_BLOCK} = 1 * IsGood[d,b] - 5 * (1 - IsGood[d,b]);
max TotalScore = sum {<d,b> in DATE_BLOCK} Score[d,b];
con CardinalityTreatment:
sum {t in TREATMENTS} SelectTreatment[t] = 2;
con CardinalityMethod:
sum {m in METHODS} SelectMethod[m] = 1;
/* SelectTreatmentMethod[t,m] <= SelectTreatment[t] * SelectMethod[m] */
con Linearize1 {t in TREATMENTS, m in METHODS}:
SelectTreatmentMethod[t,m] <= SelectTreatment[t];
con Linearize2 {t in TREATMENTS, m in METHODS}:
SelectTreatmentMethod[t,m] <= SelectMethod[m];
con AtLeastOneGood {<d,b> in DATE_BLOCK}:
IsGood[d,b] <= sum {<(d),(b),t> in DATE_BLOCK_TREATMENT,
m in METHODS: outcome[d,b,t,m] < _tmin_orig[d,b,t]} SelectTreatmentMethod[t,m];
/* call MILP solver , TOP one only*/
solve;
create data want_method from [method] SelectMethod;
create data want_treatment from [treatment] SelectTreatment;
create data want_dt_bloc from [dt bloc] IsGood Score;
create data want_x_dtbloc from [d b]=DATE_BLOCK;
create data want_trtmt from [t]=TREATMENTS;
quit;
I tried some variation, below or alike. But it complains.
/* IT WAS
impvar Score {<d,b> in DATE_BLOCK} = 1 * IsGood[d,b] - 5 * (1 - IsGood[d,b]);
max TotalScore = sum {<d,b> in DATE_BLOCK} Score[d,b];*/
var Score {<d,b> in DATE_BLOCK} = 1 * IsGood[d,b] - 5 * (1 - IsGood[d,b]);
var TotalScore = sum {<d,b> in DATE_BLOCK} Score[d,b];
impvar difx{<d,b> in DATE_BLOCK} = outcome[d,b]* IsGood[d,b]-_time_orig[b];
max TotalDif =sum {<d,b> in DATE_BLOCK} difx[d,b];
con MinScore TotalScore >=4;
Please keep # of selection of Treatment and Method BOTH=2. THanks,
con CardinalityTreatment:
sum {t in TREATMENTS} SelectTreatment[t] = 2;
con CardinalityMethod:
sum {m in METHODS} SelectMethod[m] = 2;
THanks,
... View more