1. A method for automating or partially automating optimization of a drilling operation in the hydrocarbon industry, where the drilling operation is subject to a change in one or more operating conditions, can be controlled by at least one parameter and is monitored by sensors providing input data streams, comprising: receiving input data streams indicative of depth-of-cut, weight-on-bit-and drill-bit rotational speed; upon receiving a new data item in one of the input data streams, using a processor to postulate that the input data stream is segmented according to a plurality of possible segmentations, wherein each of the plurality of possible segmentations comprises a plurality of segments divided by one or more changepoints, and wherein the changepoints are indicative of a change in at least one of the one or more operating conditions; evaluating each of the plurality of possible segmentations by: fitting portions of the input data corresponding to each segment in the segmentation being evaluated to a model corresponding to the each segment in the segmentation being evaluated; and determining how well the models for the segments of the segmentation being evaluated fit the portions of the input data corresponding to each segment of the segmentation being evaluated; generating an output in the form of a functional relationship defining rate-of-penetration (ROP) as a function of weight-on-bit and drill-bit rotational speed from at least one of the plurality of possible segmentations and the models corresponding to the segments of the at least one of the plurality of possible segmentations; determining operating constraints defining a safe operating envelope as a function of drill-bit rotational speed and weight-on-bit; determining the rotational speed and weight-on-bit parameters that provide the optimal rate-of-penetration location within the safe operating envelope; and outputting a combination of drill-bit rotational speed and weight-on-bit to move the drill-bit rotational speed and weight-on-bit towards the rotational speed and weight-on-bit parameters for the optimal rate-of-penetration location.