A non-transitory computer-readable medium encoded with computer executable instructions for automated drilling of a borehole in a subsurface formation, characterised in that when executed the computer-executable instructions cause a processor to: control drilling of a first interval of the borehole using a set of control variables populated with a set of first values; determine a first value of a drilling performance objective corresponding to drilling of the first interval of the borehole; control drilling of a second interval of the borehole using the set of control variables populated with a set of second values; determine a second value of the drilling performance objective corresponding to drilling of the second interval of the borehole; generate a set of third values for the set of control variables by: applying a first offset value to one of the set of first values and the set of second values of the control variables, the first offset value comprising a magnitude and direction; selecting one of the set of first and set of second values of the control variable to which the first offset value is applied by comparing the first value of the drilling performance objective and the second value of the drilling performance objective to a predetermined value of the drilling performance objective, and selecting the direction of the first offset value based on which of the set of first and set of second values of the control variable is applied to produce the value of the drilling performance objective nearest to the predetermined value of the drilling performance objective; and control drilling of a third interval of the borehole using the set of control variables populated with the set of third values. control drilling of a first interval of the borehole using a set of control variables populated with a set of first values; determine a first value of a drilling performance objective corresponding to drilling of the first interval of the borehole; control drilling of a second interval of the borehole using the set of control variables populated with a set of second values; determine a second value of the drilling performance objective corresponding to drilling of the second interval of the borehole; generate a set of third values for the set of control variables by: applying a first offset value to one of the set of first values and the set of second values of the control variables, the first offset value comprising a magnitude and direction; selecting one of the set of first and set of second values of the control variable to which the first offset value is applied by comparing the first value of the drilling performance objective and the second value of the drilling performance objective to a predetermined value of the drilling performance objective, and selecting the direction of the first offset value based on which of the set of first and set of second values of the control variable is applied to produce the value of the drilling performance objective nearest to the predetermined value of the drilling performance objective; and applying a first offset value to one of the set of first values and the set of second values of the control variables, the first offset value comprising a magnitude and direction; selecting one of the set of first and set of second values of the control variable to which the first offset value is applied by comparing the first value of the drilling performance objective and the second value of the drilling performance objective to a predetermined value of the drilling performance objective, and selecting the direction of the first offset value based on which of the set of first and set of second values of the control variable is applied to produce the value of the drilling performance objective nearest to the predetermined value of the drilling performance objective; and control drilling of a third interval of the borehole using the set of control variables populated with the set of third values.