flexible machining algorithm