Wednesday, 11 September 2013

How to find minimal set of operations to meet requirements

How to find minimal set of operations to meet requirements

I think it's easier, if I show my code first.
/* Machine that can add and remove pools to its stack */
public class Machine {
private final int toolQuantity = 5;
public boolean addTool(Tool t) { return true; }
public boolean removeTool(Tool t) { return true; }
public boolean processJob(Job j) { return true; }
}
/* Tool that is needed to process jobs */
class Tool {
}
/* Job that needs specific tools to be processed on machine */
class Job {
private final List<Tool> needs = Collections.emptyList();
}
interface Command { public void execute(); }
class AddTool implements Command {
private Machine m;
private Tool t;
@Override
public void execute() { }
}
class RemoveTool implements Command {
private Machine m;
private Tool t;
@Override
public void execute() { }
}
Simplyfied code. Aim was just to communicate the idea
So, I have a machine which processes jobs. Jobs need tools (and the tools
have an unlimited lifetime). My aim is to find a minimal list of jobs and
commands (i. e. instances of AddTool and RemoveTool), so that a given
fixed list of jobs can be processed.



I have two approaches:
SIMPLE
Collect requierements from job to job. Since this approach only considers
job i and job i + 1. It may not be optimal in cases where machine unloads
a tool not needed by job i + 1 but needed by job i + 2. That's an
unnecessary cycle of removing and adding (given there was the possibility
to remove another not needed tool).
HEURISTIC
Use an heuristic algorith, e. g. simulated annealing, that minimizes the
number of commands used.
I would prefer to use a straight forward aproach. But I can't think of
another and I guess the simple approach is too unefficient.
So how can I solve my problem? How can it be classified in terms of
computer science? I would also appreciate general solutions to these kind
of problems that don't specificly handle jobs, machines and tools.

No comments:

Post a Comment