Browse Source

Stock exchange sim project

content-update
MSilva95 4 years ago
parent
commit
67be16049b
  1. 237
      subjects/stock-exchange-sim/README.md
  2. 233
      subjects/stock-exchange-sim/audit/README.md
  3. 19
      subjects/stock-exchange-sim/examples/build/build
  4. 15
      subjects/stock-exchange-sim/examples/build/build.log
  5. 19
      subjects/stock-exchange-sim/examples/checkererror/testchecker
  6. 14
      subjects/stock-exchange-sim/examples/checkererror/testchecker.log
  7. 7
      subjects/stock-exchange-sim/examples/errors/error1
  8. 3
      subjects/stock-exchange-sim/examples/errors/error2
  9. 8
      subjects/stock-exchange-sim/examples/errors/error3
  10. 11
      subjects/stock-exchange-sim/examples/fertilizer/fertilizer
  11. 115606
      subjects/stock-exchange-sim/examples/fertilizer/fertilizer.log
  12. 9
      subjects/stock-exchange-sim/examples/seller/seller
  13. 24
      subjects/stock-exchange-sim/examples/seller/seller.log
  14. 18
      subjects/stock-exchange-sim/examples/simple/simple
  15. 10
      subjects/stock-exchange-sim/examples/simple/simple.log

237
subjects/stock-exchange-sim/README.md

@ -0,0 +1,237 @@
## stock-exchange-sim
### Objectives
This project consists of executing a program that will optimize the performance of a process chain, maximizing a result and/or reducing the delay as much as possible.
You must therefore run a program that, as input, reads a file that describes the processes, analyze the entire file and propose a valid solution of interest.
You will also have to create a second small checker program.
You have to create at least two process file of your own, that is not a copy/paste of the ones provided.
### Introduction
You may have already seen a project in which all tasks are linked, according to their respective dependencies and restrictions.
The goal of this program is to organize a certain chain of project tasks in order to optimize a defined task the faster and most efficient way.
Example:
Imagine a project with different tasks in witch we have to achieve a final goal. Each of the tasks can have their dependencies and restrictions, lets say you are putting together a new cabinet and you have 7 boards.
| Task | Needed | Result | Cycle |
| ------------- | :-----------------------------------: | :----------: | :---: |
| do_doorknobs | board: 1 | doorknobs:1 | 15 |
| do_background | board: 2 | background:1 | 20 |
| do_shelf | board: 1 | shelf:1 | 10 |
| do_cabinet | doorknobs: 2; background: 1; shelf: 3 | cabinet:1 | 30 |
Your purpose in this example is to optimise time and cabinet, basically the cabinet is the last product to achieve in the project and time is to be prioritized so that the building of your cabinet is done the fastest way possible.
The tasks should be done in this order to achieve a maximum optimization regarding time and cabinet:
```console
0:do_shelf
0:do_shelf
0:do_shelf
0:do_doorknobs
0:do_doorknobs
0:do_background
20:do_cabinet
# No more process doable at cycle 51
```
So the number before the task represents the cycle when the task starts. The tasks can run separately or at the same time depending on the stocks that are used.
In the example above we have the first 6 tasks beginning at cycle 0 and running at the same time, this happens because we have 7 boards and all of them can be used in the first 6 tasks without any dependencies. After the 6 tasks are finished it has already passed 20 cycles, so the next task (do_cabinet) will start at cycle 20 and end at cycle 50. This task did not start earlier because it is dependant of the results of the others.
Well, optimizing a regular schedule may help you to prioritize your tasks and make your program work with that purpose.
Priority based project scheduling is a quick and easy heuristic scheduling technique that makes use of two components to construct a resource feasible project schedule, a [priority rule and a schedule generation scheme](http://www.pmknowledgecenter.com/node/256).
Here are some ways to schedule a scheme:
- [Serial schedule generation scheme](http://www.pmknowledgecenter.com/dynamic_scheduling/baseline/optimizing-regular-scheduling-objectives-schedule-generation-schemes): selects the activities one by one from the list and schedules them as-soon-as-possible in the schedule.
- [Parallel schedule generation scheme](http://www.pmknowledgecenter.com/dynamic_scheduling/baseline/optimizing-regular-scheduling-objectives-schedule-generation-schemes): selects at each predefined time period the activities available to be scheduled and schedules them in the list as long as enough resources are available.
#### File format
First we need a configuration file that contains the processes and must obey the following instructions:
- A `#` that defines comments
- A description of the stocks available at the start, with the following format
`<stock_name>:<quantity>`
- A description of the processes:
`<name>:(<need>:<quantity>;<need>:<quantity>[...]]):(<result>:<quantity>[;result>:<quantity>[...]]):<nb_cycle>`
- A single line to indicate the elements to optimize, possibly containing the `time` keyword :
`optimize:(<stock_name>|time)`
So, as we said above, you must create at least two configuration file of your own. One file that ends when the resources are consumed, and the other which can rotate indefinitely.
### Stock exchange program
Then we can run the **The stock exchange program** to generate a schedule.
- It takes 2 parameters:
`./stock_exchange <file> <waiting_time>`
- The first is the `configuration file` with all stocks and processes. The second parameter is a waiting time that the program should not exceed in seconds.
- In the situation where the resources will be consumed and the processes will stop, due to the lack of resources, the display will go all the way without errors.
- In the situation where the system self-powers and rotates indefinitely, you will choose a reasonable shutdown condition, and your stocks should show that the whole process went well several times.
- There is no obligation of invariance between two executions. This means that, for the same configuration, the first recommended solution, may be completely different from the second one.
- It is up to you to create and organize the display, it must nevertheless allow the understanding of the main actions carried out by the program.
```console
Main Processes :
0:do_shelf
0:do_shelf
0:do_shelf
0:do_doorknobs
0:do_doorknobs
0:do_background
20:do_cabinet
No more process doable at cycle 51
Stock :
board => 0
doorknobs => 0
background => 0
shelf => 0
cabinet => 1
```
- The display must also produce an output usable by the verification program, in the following format:
`<cycle>: <process_name>`
The generated schedule is then saved as a log in the example folder with the same name.
So if you run:
```console
student$ ./stock examples/simple 10
```
You get this generated schedule:
```console
student$ cat examples/simple.log
0:buy_materiel
10:build_product
40:delivery
# No more process doable at cycle 61
```
### Checker
We can then verify if the schedule is doable with the **checker** program:
- It takes 2 parameters:
`.\checker <file> <result_to_test>`
- The first parameter is the configuration file, the second is a log file containing the trace of stock exchange program which must be checked.
- The display must indicate whether the sequence is correct, or indicate the cycle and the process which are causing the problem. In all cases, at the end of the program, stocks are displayed, as well as the last cycle.
#### Example
- Configuration file:
```
#
# simple example
#
# stock
name:quantity
euro:10
#
# process
name:(need1:quantity1;need2:quantity2;[...]):(result1:quantity1;result2:quantity2;[...]):delay
#
buy_materiel:(euro:8):(material:1):10
build_product:(material:1):(product:1):30
delivery:(product:1):(client_content:1):20
#
# optimize time for no process possible (eating stock, produce all possible),
# or maximize some products over a long delay
# optimize:(time|stock1;time|stock2;...)
#
optimize:(time;client_content)
#
```
### Usage
Running the stock exchange program:
```
student$ ./stock examples/simple 10
Main Processes :
0:buy_materiel
10:build_product
40:delivery
No more process doable at cycle 61
Stock :
euro => 2
materiel => 0
product => 0
client_content => 1
student$
```
Running the checker program:
```
student$ ./checker examples/simple examples/simple.log
Evaluating: 0:buy_materiel
Evaluating: 10:build_product
Evaluating: 40:delivery
Trace completed, no error detected.
student$
```
----
Running the stock exchange program with error:
```console
student$ cat examples/simple
euro:10
:(euro:8):(material:1):10
build_product:(material:1):(product:1):30
delivery:(product:1):(client_content:1):20
optimize:(time;client_content)
student$ ./stock examples/simple 10
Error while parsing `:(euro:8):(material:1):10`
student$
```
Running the checker program with error:
```console
student$ cat examples/simple.log
0:buy_materiel
10:build_product
10:build_product
40:delivery
# No more process doable at cycle 61
student$ ./checker examples/simple examples/simple.log
Evaluating: 0:buy_materiel
Evaluating: 10:build_product
Evaluating: 10:build_product
Evaluating: 40:delivery
Error detected
at 10:build_product stock insufficient
student$
```

233
subjects/stock-exchange-sim/audit/README.md

@ -0,0 +1,233 @@
### General
###### Can you confirm that the program reads a file that describes the processes, analyze the entire file and propose a valid solution?
###### Does the project contains a checker program?
###### Can you confirm that at least two configuration files were made by the project owner?
###### Can you confirm that those files are not a copy/paste of the ones provided?
###### Can you confirm that one of those files ends when the resources are consumed and the other one rotate indefinitely?
###### Can you confirm that those files obey the given file format?
### Functional
##### Try to run the stock exchange program with the files created by the owner of the project.
###### Can you confirm that those files are working with the program?
##### Try to run the stock exchange program with the files created by the owner of the project.
###### Does the program produces a log file?
###### Can that log file be used by the checker program?
##### Try to run the stock exchange program with the [simple](https://public.01-edu.org/subjects/stock-exchange-sim/examples/simple/simple) example, `"./stock examples/simple/simple 1"`.
```console
student$ ./stock examples/simple/simple 1
Main Processes :
0:buy_materiel
10:build_product
40:delivery
No more process doable at cycle 61
Stock :
euro => 2
materiel => 0
product => 0
client_content => 1
student$
```
###### Does the display presents a result similar to the one above (optimizing time;client_content)?
##### Try to run the stock exchange program with the [build](https://public.01-edu.org/subjects/stock-exchange-sim/examples/build/build) example, `"./stock examples/build/build 10"`.
```console
student$ ./stock examples/build/build 10
Main Processes :
0:do_shelf
0:do_shelf
0:do_shelf
0:do_doorknobs
0:do_doorknobs
0:do_background
20:do_cabinet
No more process doable at cycle 51
Stock :
board => 0
doorknobs => 0
background => 0
shelf => 0
cabinet => 1
student$
```
###### Does the display presents a result similar to the one above (optimizing time;cabinet)?
##### Try to run the stock exchange program with the [seller](https://public.01-edu.org/subjects/stock-exchange-sim/examples/seller/seller) example, `"./stock examples/seller/seller 10"`.
```console
student$ ./stock examples/seller/seller 10
Main Processes :
0:optimize_profile
0:code
1:code
101:optimize_profile
101:sell_skills
101:sell_skills
101:code
102:code
111:code
211:optimize_profile
211:sell_skills
211:sell_skills
212:sell_skills
212:code
222:code
322:sell_skills
No more process doable at cycle 333
Stock :
repos => 0
transport => 0
skills => 1
fame => 0
euro => 601
student$
```
###### Does the display presents a result similar to the one above (optimizing euro)?
##### Try to run the stock exchange program with the [fertilizer](https://public.01-edu.org/subjects/stock-exchange-sim/examples/fertilizer/fertilizer) example, `"./stock examples/fertilizer/fertilizer 1"`.(fertilizer example is self-powered and rotates indefinitely)
```console
student$ ./stock examples/fertilizer/fertilizer 1
Main Processes :
...
3973515:eat_apple
3973516:plant_apple
3973616:pick_apple
3973620:eat_apple
3973621:plant_apple
3973721:pick_apple
3973725:eat_apple
No more process doable at cycle 3973727
Stock :
apple => 0
you => 1
seed => 1
fertilizer => 1
happiness => 37846
apple_tree => 0
student$
```
###### Does the display presents a result similar to the one above, (optimizing happiness), choosing a reasonable shutdown condition and showing that the whole process went well for several times?
##### Run the same example with a different waiting time `"./stock examples/fertilizer/fertilizer 0.0003"`.(fertilizer example is self-powered and rotates indefinitely)
###### Does the display presents a result significantly shorter number of cycles comparing to the previous question output?
##### Try to run the stock exchange program with the [error1](https://public.01-edu.org/subjects/stock-exchange-sim/examples/errors/error1) example, `"./stock examples/errors/error1 1"`.
```console
student$ ./stock examples/errors/error1 1
Error while parsing `:(euro:8):(material:1):10`
Exiting...
student$
```
###### Does the display presents a result similar to the one above, were it shows the error?
##### Try to run the stock exchange program with the [error2](https://public.01-edu.org/subjects/stock-exchange-sim/examples/errors/error2) example, `"./stock examples/errors/error2 1"`.
```console
student$ ./stock examples/errors/error2 1
Missing processes
Exiting...
student$
```
###### Does the display presents a result similar to the one above, were it shows the error?
##### Try to run the stock exchange program with the [error3](https://public.01-edu.org/subjects/stock-exchange-sim/examples/errors/error3) example, `"./stock examples/errors/error3 1"`.
```console
student$ ./stock examples/errors/error3 1
Error while parsing `optimize:(euro)`
Exiting...
student$
```
###### Does the display presents a result similar to the one above, were it shows the error?
##### Try to run the checker program with the [build](https://public.01-edu.org/subjects/stock-exchange-sim/examples/build/build) example, `"./checker examples/build/build examples/build/build.log"`.
```console
student$ ./checker examples/build/build examples/build/build.log
Evaluating: 0:do_shelf
Evaluating: 0:do_shelf
Evaluating: 0:do_shelf
Evaluating: 0:do_doorknobs
Evaluating: 0:do_doorknobs
Evaluating: 0:do_background
Evaluating: 20:do_cabinet
Trace completed, no error detected.
student$
```
###### Does the display presents a result similar to the one above, were it shows the last cycle and the proof that the sequence is correct?
##### Try to run the checker program with the [seller](https://public.01-edu.org/subjects/stock-exchange-sim/examples/seller/seller) example, `"./checker examples/seller/seller examples/seller/seller.log"`.
```console
student$ ./checker examples/seller/seller examples/seller/seller.log
Evaluating: 0:optimize_profile
Evaluating: 0:code
Evaluating: 1:code
Evaluating: 101:optimize_profile
Evaluating: 101:sell_skills
Evaluating: 101:sell_skills
Evaluating: 101:code
Evaluating: 102:code
Evaluating: 111:code
Evaluating: 211:optimize_profile
Evaluating: 211:sell_skills
Evaluating: 211:sell_skills
Evaluating: 212:sell_skills
Evaluating: 212:code
Evaluating: 222:code
Evaluating: 322:sell_skills
Trace completed, no error detected.
student$
```
###### Does the display presents a result similar to the one above, where it shows the last cycle and the proof that the sequence is correct?
##### Try to run the checker program with the [testchecker](https://public.01-edu.org/subjects/stock-exchange-sim/examples/checkererror/testchecker) and [testchecker.log](https://public.01-edu.org/subjects/stock-exchange-sim/examples/checkererror/testchecker.log) example, `"./checker examples/checkererror/testchecker examples/checkererror/testchecker.log"`.
```console
student$ ./checker examples/checkererror/testchecker examples/checkererror/testchecker.log
Evaluating: 0:do_shelf
Evaluating: 0:do_shelf
Evaluating: 0:do_doorknobs
Evaluating: 0:do_doorknobs
Evaluating: 0:do_background
Evaluating: 20:do_cabinet
Error detected
at 20:do_cabinet stock insufficient
Exiting...
student$
```
###### Does the display presents a result similar to the one above, where it shows the last cycle and the proof that the sequence has errors?
#### Bonus
###### +Does the project runs quickly and effectively? (Favoring recursive, no unnecessary data requests, etc)
###### +Does the code obey the [good practices](https://public.01-edu.org/subjects/good-practices/README.md)?
###### +Can the users create their own files to run in the program?

19
subjects/stock-exchange-sim/examples/build/build

@ -0,0 +1,19 @@
#
# build demo - stock
#
# stock name:quantity
board:7
#
# process name:(need1:qty1;need2:qty2;[...]):(result1:qty1;result2:qty2;[...]):delay
#
do_doorknobs:(board:1):(doorknobs:1):15
do_background:(board:2):(background:1):20
do_shelf:(board:1):(shelf:1):10
do_cabinet:(doorknobs:2;background:1;shelf:3):(cabinet:1):30
#
# optimize time for 0 stock and no process possible,
# or maximize some products over a long delay
# optimize:(stock1;stock2;...)
#
optimize:(time;cabinet)
#

15
subjects/stock-exchange-sim/examples/build/build.log

@ -0,0 +1,15 @@
# Main walk
0:do_shelf
0:do_shelf
0:do_shelf
0:do_doorknobs
0:do_doorknobs
0:do_background
20:do_cabinet
# No more process doable at cyle 51
# Stock :
# board => 0
# doorknobs => 0
# background => 0
# shelf => 0
# cabinet => 1

19
subjects/stock-exchange-sim/examples/checkererror/testchecker

@ -0,0 +1,19 @@
#
# build demo - stock
#
# stock name:quantity
board:7
#
# process name:(need1:qty1;need2:qty2;[...]):(result1:qty1;result2:qty2;[...]):delay
#
do_doorknobs:(board:1):(doorknobs:1):15
do_background:(board:2):(background:1):20
do_shelf:(board:1):(shelf:1):10
do_cabinet:(doorknobs:2;background:1;shelf:3):(cabinet:1):30
#
# optimize time for 0 stock and no process possible,
# or maximize some products over a long delay
# optimize:(stock1;stock2;...)
#
optimize:(time;cabinet)
#

14
subjects/stock-exchange-sim/examples/checkererror/testchecker.log

@ -0,0 +1,14 @@
# Main walk
0:do_shelf
0:do_shelf
0:do_doorknobs
0:do_doorknobs
0:do_background
20:do_cabinet
# No more process doable at cyle 51
# Stock :
# board => 0
# doorknobs => 0
# background => 0
# shelf => 0
# cabinet => 1

7
subjects/stock-exchange-sim/examples/errors/error1

@ -0,0 +1,7 @@
euro:10
:(euro:8):(material:1):10
build_product:(material:1):(product:1):30
delivery:(product:1):(client_content:1):20
optimize:(time;client_content)

3
subjects/stock-exchange-sim/examples/errors/error2

@ -0,0 +1,3 @@
euro:10
optimize:(time;client_content)

8
subjects/stock-exchange-sim/examples/errors/error3

@ -0,0 +1,8 @@
euro:10
buy_material:(euro:8):(material:1):10
build_product:(material:1):(product:1):30
delivery:(product:1):(client_content:1):20
optimize:(time;client_content)
optimize:(euro)

11
subjects/stock-exchange-sim/examples/fertilizer/fertilizer

@ -0,0 +1,11 @@
#fertilizer
apple:1
you:1
#
#
eat_apple:(apple:1;you:1):(you:1;seed:1;fertilizer:1;happiness:1):1
plant_apple:(you:1;seed:1;fertilizer:1):(you:1;apple_tree:1):100
pick_apple:(you:1;apple_tree:1):(you:1;apple:1):4
#
optimize:(happiness)
#

115606
subjects/stock-exchange-sim/examples/fertilizer/fertilizer.log

File diff suppressed because it is too large diff.load

9
subjects/stock-exchange-sim/examples/seller/seller

@ -0,0 +1,9 @@
repos:100
transport:0
skills:0
fame:0
euro:1
code:(repos:10):(skills:1):100
optimize_profile:(repos:10):(fame:20):1
sell_skills:(skills:1;fame:10):(euro:100):10
optimize:(euro)

24
subjects/stock-exchange-sim/examples/seller/seller.log

@ -0,0 +1,24 @@
# Main walk
0:optimize_profile
0:code
1:code
101:optimize_profile
101:sell_skills
101:sell_skills
101:code
102:code
111:code
211:optimize_profile
211:sell_skills
211:sell_skills
212:sell_skills
212:code
222:code
322:sell_skills
# No more process doable at cyle 333
# Stock :
# repos => 0
# transport => 0
# skills => 1
# fame => 0
# euro => 601

18
subjects/stock-exchange-sim/examples/simple/simple

@ -0,0 +1,18 @@
#
# simple example
#
# stock name:quantity
euro:10
#
# process name:(need1:quantity1;need2:quantity2;[...]):(result1:quantity1;result2:quantity2;[...]):delay
#
buy_materiel:(euro:8):(materiel:1):10
build_product:(materiel:1):(product:1):30
delivery:(product:1):(client_content:1):20
#
# optimize time for no process possible (eating stock, produce all possible),
# or maximize some products over a long delay
# optimize:(time|stock1;time|stock2;...)
#
optimize:(time;client_content)
#

10
subjects/stock-exchange-sim/examples/simple/simple.log

@ -0,0 +1,10 @@
# Main walk
0:buy_materiel
10:build_product
40:delivery
# No more process doable at cyle 61
# Stock :
# euro => 2
# materiel => 0
# product => 0
# client_content => 1
Loading…
Cancel
Save