array[int] of int: readings; int: start; int: n = length(readings); array[0..n] of var 25..30: temp; % temp[i] is building temperature at time i enum PROCESS = {heat,strongly_heat,cool,strongly_cool,do_nothing}; % the process that can be performed array[1..n] of var PROCESS: action; % action[i] is temp control process taken at time i array[1..n] of var int: cost; % the cost of the action at time i array[PROCESS] of int: deltaT = [1,4,-2,-5,0]; % the effect of a process on temperature array[PROCESS] of int: actionCost = [1,5,3,9,0]; % the cost of a process var int: totalCost; % just so we can print off total cost of solution constraint temp[0] = start; constraint forall(i in 1..n) (temp[i] = ((temp[i-1] + readings[i]) div 2 + deltaT[action[i]])); constraint forall(i in 1..n) (cost[i] = actionCost[action[i]]); constraint totalCost = sum(cost); solve minimize totalCost; output ["temp = \(temp) \n"]; output ["choice = \(action) \n"]; output ["cost = \(totalCost)"]