2

i am writing a simulation about vehicle manufacturing, i am wondering how i can create objects based on time..

i have a base class Vehicle, and children Motorbike, Car, and Truck. 1 Motorbike will be manufactured every 1 hour, 1 car will be manufactured every 3 hours, and 1 truck will be manufactured every 8 hours.

how can i create those objects according to the time indicated?

thanks

3
  • You are referring to simulation time? If so, how are you driving the simulation? Are you using fixed time increments, elapsed real-time times N, ...? Sep 8, 2010 at 3:36
  • i am using real time, but later on i want to speed up the time, let say 1 month in the program = 10 minute real time Sep 8, 2010 at 5:06
  • And do all productions start and end at a fixed multiple of a basic time unit (e.g. C * 1h)? Or at arbitrary points? Sep 8, 2010 at 20:31

3 Answers 3

1

One possibility is to have a thread dedicated to each task, that just sits in a loop of lather, rinse,create, sleep, repeat.

1

You can create timers and wait on those timer events. When the timer expires you can create corresponding object. You can monitor this in a thread.

When will you be destroying these objects?

1
  • the manufactured vehicle will go to some processes then they will be destroyed Sep 8, 2010 at 3:39
0

If you want to have complete control over the timing (say, you can increment the time irrespective of the system timer), then you'll need to implement that as a class. Then provide a Singleton or static function to return the Current time. The time class should be copyable so that objects can remember the starting time. Also, provide a function for advancing time by a certain amount, and for doing time comparisons.

Inside each manufacturable object (or better, the factories that manufacture them), add two functions:

  1. StartManufacture. This function should remember the starting time.
  2. CheckManufactureComplete. This function fetches the current time, and checks if the required waiting time has elapsed since manufacturing started.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.