...
1
18
19 package api
20
21 import (
22 "net/http"
23 "scheduler/log"
24 "scheduler/service_learning"
25 "time"
26 )
27
28 var learningDevTestEid = 0
29
30 func LearningDevTestAct(w http.ResponseWriter, r *http.Request) {
31 entry := service_learning.EntryAct{State: []float64{1.0, 2.3, 1.8}}
32 action, err := service_learning.Act(&entry)
33
34 if err != nil {
35 log.Log.Errorf("Cannot take decision: %s", err)
36 } else {
37 log.Log.Debugf("Taken decision: %f", action)
38 }
39
40 w.WriteHeader(200)
41 }
42
43 func LearningDevTestActWs(w http.ResponseWriter, r *http.Request) {
44 timeStart := time.Now()
45
46 entry := service_learning.EntryAct{State: []float64{1.0, 2.3, 1.8}}
47 action, err := service_learning.SocketAct(&entry)
48
49 timeEnd := time.Now()
50
51 if err != nil {
52 log.Log.Errorf("Cannot take decision: %s", err)
53 } else {
54 log.Log.Debugf("Taken decision: %f", action)
55 }
56
57 log.Log.Debugf("Elapsed time: %fms", (float64(timeEnd.UnixNano())-float64(timeStart.UnixNano()))/1000000)
58
59 w.WriteHeader(200)
60 }
61
62 func LearningDevTestTrain(w http.ResponseWriter, r *http.Request) {
63 entry := service_learning.EntryLearning{
64 Eid: learningDevTestEid,
65 State: []float64{1.2, 1.0, 1.6},
66 Action: 2,
67 Reward: 1.3,
68 }
69 err := service_learning.Train(&entry)
70
71 learningDevTestEid += 1
72
73 if err != nil {
74 log.Log.Errorf("Cannot take decision: %s", err)
75 } else {
76 log.Log.Debugf("Ok")
77 }
78
79 w.WriteHeader(200)
80 }
81
View as plain text