-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMSetting.cs
141 lines (114 loc) · 4.47 KB
/
IMSetting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class IMSetting : MonoBehaviour
{
public IMCarTracker carTracker;
public TRManager trManager;
public ModifiedSpawnerManager spawnerManager;
public IMAgent agent;
/// <summary>
/// text object that write various informations to Canvas
/// </summary>
public Text textInfo;
public Text textInfo2;
/// <summary>
/// var that increases when ResetEnv() called
/// </summary>
private int episodeNum = 0;
private int ResetCalled = 0;
/// <summary>
/// informations that write on the canvas
/// </summary>
private string infosWriteOn;
private string infosWriteOn2;
/// <summary>
/// time multiplier
/// </summary>
public float timeMultiplier = 1f;
/// <summary>
/// action that get from agent
/// </summary>
public int actionGet = 0;
private string laneMultiplierString = "";
// Start is called before the first frame update
void Start()
{
carTracker.InitializeMe();
trManager.InitializeMe();
spawnerManager.Initalize();
}
private void Update()
{
InfoUpdateOnScene();
}
void InfoUpdateOnScene()
{
infosWriteOn = "allowed Wait Time : " + carTracker.allowedWaitTime.ToString() + "\n" +
"Max Car : " + agent.maxCar.ToString() + "\n" +
"Time Multiplier : " + timeMultiplier.ToString() + "\n" +
"Lane Multiplier : " + laneMultiplierString + "\n";
infosWriteOn2 = // "Before Step Avg Waiting Time : " + agent.beforeStepAvgWaitTime.ToString() + "\n" +
"Average Wait Time : " + carTracker.ReturnAvgWaitTime().ToString() + "\n" +
"Average Travel Time : " + carTracker.ReturnAvgTravelTime().ToString() + "\n" +
"Car Counter : " + carTracker.carCounter.ToString() + "\n" +
"Step Reward : " + (agent.stepRewardGiven).ToString() + "\n" +
"Reward at end of episode : " + (agent.episodeRewardGiven).ToString() + "\n" +
"Action from Agent : " + (actionGet != 12 ? actionGet.ToString() : "no-op") + "\n\n";
textInfo.text = infosWriteOn;
textInfo2.text = infosWriteOn2;
}
void InfoUpdateOnDebugLog()
{
Debug.Log("... EPISODE INFOS FROM ENV ..." + "\n" +
"allowed Wait Time : " + carTracker.allowedWaitTime.ToString() + "\n" +
"Max Car : " + agent.maxCar.ToString() + "\n" +
"Time Multiplier : " + timeMultiplier.ToString() + "\n" +
"Lane Multiplier : " + laneMultiplierString + "\n" +
"Average Wait Time : " + carTracker.ReturnAvgWaitTime().ToString() + "\n" +
"Average Travel Time : " + carTracker.ReturnAvgTravelTime().ToString() + "\n"
);
}
public void ResetEnv()
{
Time.timeScale = 0;
spawnerManager.ResetEnv();
carTracker.ResetEnv();
trManager.ResetEnv();
if (ResetCalled == 0)
spawnerManager.trafficSpawner.isBegin = false;
Time.timeScale = timeMultiplier;
ResetCalled++;
if(Application.platform == RuntimePlatform.LinuxServer || Application.platform == RuntimePlatform.WindowsServer)
{
InfoUpdateOnDebugLog();
}
}
/// <summary>
/// set env's parameter
/// </summary>
/// <param name="msg"> message get from IMRLEnv_main.py </param>
public void EnvSetting(string msg)
{
// decode msg
string[] decodeMsg = msg.Split(',');
int isEnvInitNeeded = int.Parse(decodeMsg[0]);
episodeNum = int.Parse(decodeMsg[1]);
if (isEnvInitNeeded != 0)
{
spawnerManager.amountCarAtScene = int.Parse(decodeMsg[2]);
carTracker.allowedWaitTime = float.Parse(decodeMsg[3]);
agent.maxCar = (spawnerManager.amountCarAtScene * 1.5f);
timeMultiplier = float.Parse(decodeMsg[4]);
spawnerManager.allowedLaneMultiplier = new float[12];
laneMultiplierString = "";
for (int i = 0; i < 12; i++)
{
laneMultiplierString += decodeMsg[i + 5];
laneMultiplierString += " ";
spawnerManager.allowedLaneMultiplier[i] = float.Parse(decodeMsg[i + 5]);
}
}
}
}