Problem Description
This chapter describes the general problem and the initial way to setup a model for it.
Introduction
A company is making a scheduling tool to control robots. The company has multiple factories. Each factory has a list of Jobs with a position and duration in time, as well as a Task. Task can be various, and one of them is about command robots. All robots have exactly 128 arms, and each arm can receive commands. Commands are described with an opcode, and a position and duration in time.
Jobs can't overlap, as well as commands for one robot arm.
The company decides to implement this model, and makes the following decisions :
- The number of commands might be big, so it is implemented with
Vector
. The commands are ordered by position to allow fast search of events. - Arms are implemented as an
Array
- Jobs are ordered in an
Array
by position to allow faster search of events
Implementation
The initial model, Model1
is implemented as below :
class Model1 : public DataModel <Model1> {}; |
class Command |
{ |
public: |
double position; |
double duration; |
uint64_t opcode; |
}; |
class RobotArm : public Object |
{ |
public: |
Vector <Command> commands; |
}; |
class Task : public Object {}; |
class TaskRobot : public Task |
{ |
public: |
Array <RobotArm> arms; |
}; |
class Job : public Object |
{ |
public: |
Float position; |
Float duration; |
Variant <Task> task; |
}; |
class Factory : public Object |
{ |
public: |
Array <Job> jobs; |
}; |
class Company : public Object |
{ |
public: |
Array <Factory> factories; |
}; |
This model is almost totally right implemented like that. However We are going to see some technics to optimize it, when the problem dimension gets bigger.
It is going to be refined in 4 successive passes.
All models are implemented and can be found in test/perf/PerfRealLife2.cpp/h
The next chapter, Refining Arms, exposes a first easy and quite common optimisation.