TJIET commited on
Commit
bcba0e4
·
verified ·
1 Parent(s): 5d8dbc0

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -57,3 +57,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
+ minari_export/minari_MPC/data/dataset.json filter=lfs diff=lfs merge=lfs -text
61
+ minari_export/minari_Rule/data/dataset.json filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### PyCharm+iml template
2
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
3
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
4
+
5
+ # User-specific stuff
6
+ .idea/**/workspace.xml
7
+ .idea/**/tasks.xml
8
+ .idea/**/usage.statistics.xml
9
+ .idea/**/dictionaries
10
+ .idea/**/shelf
11
+
12
+ # AWS User-specific
13
+ .idea/**/aws.xml
14
+
15
+ # Generated files
16
+ .idea/**/contentModel.xml
17
+
18
+ # Sensitive or high-churn files
19
+ .idea/**/dataSources/
20
+ .idea/**/dataSources.ids
21
+ .idea/**/dataSources.local.xml
22
+ .idea/**/sqlDataSources.xml
23
+ .idea/**/dynamic.xml
24
+ .idea/**/uiDesigner.xml
25
+ .idea/**/dbnavigator.xml
26
+
27
+ # Gradle
28
+ .idea/**/gradle.xml
29
+ .idea/**/libraries
30
+
31
+ # Gradle and Maven with auto-import
32
+ # When using Gradle or Maven with auto-import, you should exclude module files,
33
+ # since they will be recreated, and may cause churn. Uncomment if using
34
+ # auto-import.
35
+ # .idea/artifacts
36
+ # .idea/compiler.xml
37
+ # .idea/jarRepositories.xml
38
+ # .idea/modules.xml
39
+ # .idea/*.iml
40
+ # .idea/modules
41
+ # *.iml
42
+ # *.ipr
43
+
44
+ # CMake
45
+ cmake-build-*/
46
+
47
+ # Mongo Explorer plugin
48
+ .idea/**/mongoSettings.xml
49
+
50
+ # File-based project format
51
+ *.iws
52
+
53
+ # IntelliJ
54
+ out/
55
+
56
+ # mpeltonen/sbt-idea plugin
57
+ .idea_modules/
58
+
59
+ # JIRA plugin
60
+ atlassian-ide-plugin.xml
61
+
62
+ # Cursive Clojure plugin
63
+ .idea/replstate.xml
64
+
65
+ # SonarLint plugin
66
+ .idea/sonarlint/
67
+
68
+ # Crashlytics plugin (for Android Studio and IntelliJ)
69
+ com_crashlytics_export_strings.xml
70
+ crashlytics.properties
71
+ crashlytics-build.properties
72
+ fabric.properties
73
+
74
+ # Editor-based Rest Client
75
+ .idea/httpRequests
76
+
77
+ # Android studio 3.1+ serialized cache file
78
+ .idea/caches/build_file_checksums.ser
79
+
80
+ ### JetBrains+all template
81
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
82
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
83
+
84
+ # User-specific stuff
85
+ .idea/**/workspace.xml
86
+ .idea/**/tasks.xml
87
+ .idea/**/usage.statistics.xml
88
+ .idea/**/dictionaries
89
+ .idea/**/shelf
90
+
91
+ # AWS User-specific
92
+ .idea/**/aws.xml
93
+
94
+ # Generated files
95
+ .idea/**/contentModel.xml
96
+
97
+ # Sensitive or high-churn files
98
+ .idea/**/dataSources/
99
+ .idea/**/dataSources.ids
100
+ .idea/**/dataSources.local.xml
101
+ .idea/**/sqlDataSources.xml
102
+ .idea/**/dynamic.xml
103
+ .idea/**/uiDesigner.xml
104
+ .idea/**/dbnavigator.xml
105
+
106
+ # Gradle
107
+ .idea/**/gradle.xml
108
+ .idea/**/libraries
109
+
110
+ # Gradle and Maven with auto-import
111
+ # When using Gradle or Maven with auto-import, you should exclude module files,
112
+ # since they will be recreated, and may cause churn. Uncomment if using
113
+ # auto-import.
114
+ # .idea/artifacts
115
+ # .idea/compiler.xml
116
+ # .idea/jarRepositories.xml
117
+ # .idea/modules.xml
118
+ # .idea/*.iml
119
+ # .idea/modules
120
+ # *.iml
121
+ # *.ipr
122
+
123
+ # CMake
124
+ cmake-build-*/
125
+
126
+ # Mongo Explorer plugin
127
+ .idea/**/mongoSettings.xml
128
+
129
+ # File-based project format
130
+ *.iws
131
+
132
+ # IntelliJ
133
+ out/
134
+
135
+ # mpeltonen/sbt-idea plugin
136
+ .idea_modules/
137
+
138
+ # JIRA plugin
139
+ atlassian-ide-plugin.xml
140
+
141
+ # Cursive Clojure plugin
142
+ .idea/replstate.xml
143
+
144
+ # SonarLint plugin
145
+ .idea/sonarlint/
146
+
147
+ # Crashlytics plugin (for Android Studio and IntelliJ)
148
+ com_crashlytics_export_strings.xml
149
+ crashlytics.properties
150
+ crashlytics-build.properties
151
+ fabric.properties
152
+
153
+ # Editor-based Rest Client
154
+ .idea/httpRequests
155
+
156
+ # Android studio 3.1+ serialized cache file
157
+ .idea/caches/build_file_checksums.ser
158
+
159
+ ### JetBrains template
160
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
161
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
162
+
163
+ # User-specific stuff
164
+ .idea/**/workspace.xml
165
+ .idea/**/tasks.xml
166
+ .idea/**/usage.statistics.xml
167
+ .idea/**/dictionaries
168
+ .idea/**/shelf
169
+
170
+ # AWS User-specific
171
+ .idea/**/aws.xml
172
+
173
+ # Generated files
174
+ .idea/**/contentModel.xml
175
+
176
+ # Sensitive or high-churn files
177
+ .idea/**/dataSources/
178
+ .idea/**/dataSources.ids
179
+ .idea/**/dataSources.local.xml
180
+ .idea/**/sqlDataSources.xml
181
+ .idea/**/dynamic.xml
182
+ .idea/**/uiDesigner.xml
183
+ .idea/**/dbnavigator.xml
184
+
185
+ # Gradle
186
+ .idea/**/gradle.xml
187
+ .idea/**/libraries
188
+
189
+ # Gradle and Maven with auto-import
190
+ # When using Gradle or Maven with auto-import, you should exclude module files,
191
+ # since they will be recreated, and may cause churn. Uncomment if using
192
+ # auto-import.
193
+ # .idea/artifacts
194
+ # .idea/compiler.xml
195
+ # .idea/jarRepositories.xml
196
+ # .idea/modules.xml
197
+ # .idea/*.iml
198
+ # .idea/modules
199
+ # *.iml
200
+ # *.ipr
201
+
202
+ # CMake
203
+ cmake-build-*/
204
+
205
+ # Mongo Explorer plugin
206
+ .idea/**/mongoSettings.xml
207
+
208
+ # File-based project format
209
+ *.iws
210
+
211
+ # IntelliJ
212
+ out/
213
+
214
+ __pycache__/
215
+
216
+ # mpeltonen/sbt-idea plugin
217
+ .idea_modules/
218
+
219
+ # JIRA plugin
220
+ atlassian-ide-plugin.xml
221
+
222
+ # Cursive Clojure plugin
223
+ .idea/replstate.xml
224
+
225
+ # SonarLint plugin
226
+ .idea/sonarlint/
227
+
228
+ # Crashlytics plugin (for Android Studio and IntelliJ)
229
+ com_crashlytics_export_strings.xml
230
+ crashlytics.properties
231
+ crashlytics-build.properties
232
+ fabric.properties
233
+
234
+ # Editor-based Rest Client
235
+ .idea/httpRequests
236
+
237
+ # Android studio 3.1+ serialized cache file
238
+ .idea/caches/build_file_checksums.ser
239
+
240
+ ### PyCharm template
241
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
242
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
243
+
244
+ # User-specific stuff
245
+ .idea/**/workspace.xml
246
+ .idea/**/tasks.xml
247
+ .idea/**/usage.statistics.xml
248
+ .idea/**/dictionaries
249
+ .idea/**/shelf
250
+
251
+ # AWS User-specific
252
+ .idea/**/aws.xml
253
+
254
+ # Generated files
255
+ .idea/**/contentModel.xml
256
+
257
+ # Sensitive or high-churn files
258
+ .idea/**/dataSources/
259
+ .idea/**/dataSources.ids
260
+ .idea/**/dataSources.local.xml
261
+ .idea/**/sqlDataSources.xml
262
+ .idea/**/dynamic.xml
263
+ .idea/**/uiDesigner.xml
264
+ .idea/**/dbnavigator.xml
265
+
266
+ # Gradle
267
+ .idea/**/gradle.xml
268
+ .idea/**/libraries
269
+
270
+ # Gradle and Maven with auto-import
271
+ # When using Gradle or Maven with auto-import, you should exclude module files,
272
+ # since they will be recreated, and may cause churn. Uncomment if using
273
+ # auto-import.
274
+ # .idea/artifacts
275
+ # .idea/compiler.xml
276
+ # .idea/jarRepositories.xml
277
+ # .idea/modules.xml
278
+ # .idea/*.iml
279
+ # .idea/modules
280
+ # *.iml
281
+ # *.ipr
282
+
283
+ # CMake
284
+ cmake-build-*/
285
+
286
+ # Mongo Explorer plugin
287
+ .idea/**/mongoSettings.xml
288
+
289
+ # File-based project format
290
+ *.iws
291
+
292
+ # IntelliJ
293
+ out/
294
+
295
+ # mpeltonen/sbt-idea plugin
296
+ .idea_modules/
297
+
298
+ # JIRA plugin
299
+ atlassian-ide-plugin.xml
300
+
301
+ # Cursive Clojure plugin
302
+ .idea/replstate.xml
303
+
304
+ # SonarLint plugin
305
+ .idea/sonarlint/
306
+
307
+ # Crashlytics plugin (for Android Studio and IntelliJ)
308
+ com_crashlytics_export_strings.xml
309
+ crashlytics.properties
310
+ crashlytics-build.properties
311
+ fabric.properties
312
+
313
+ # Editor-based Rest Client
314
+ .idea/httpRequests
315
+
316
+ # Android studio 3.1+ serialized cache file
317
+ .idea/caches/build_file_checksums.ser
318
+
319
+ ### JetBrains+iml template
320
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
321
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
322
+
323
+ # User-specific stuff
324
+ .idea/**/workspace.xml
325
+ .idea/**/tasks.xml
326
+ .idea/**/usage.statistics.xml
327
+ .idea/**/dictionaries
328
+ .idea/**/shelf
329
+
330
+ # AWS User-specific
331
+ .idea/**/aws.xml
332
+
333
+ # Generated files
334
+ .idea/**/contentModel.xml
335
+
336
+ # Sensitive or high-churn files
337
+ .idea/**/dataSources/
338
+ .idea/**/dataSources.ids
339
+ .idea/**/dataSources.local.xml
340
+ .idea/**/sqlDataSources.xml
341
+ .idea/**/dynamic.xml
342
+ .idea/**/uiDesigner.xml
343
+ .idea/**/dbnavigator.xml
344
+
345
+ # Gradle
346
+ .idea/**/gradle.xml
347
+ .idea/**/libraries
348
+
349
+ # Gradle and Maven with auto-import
350
+ # When using Gradle or Maven with auto-import, you should exclude module files,
351
+ # since they will be recreated, and may cause churn. Uncomment if using
352
+ # auto-import.
353
+ # .idea/artifacts
354
+ # .idea/compiler.xml
355
+ # .idea/jarRepositories.xml
356
+ # .idea/modules.xml
357
+ # .idea/*.iml
358
+ # .idea/modules
359
+ # *.iml
360
+ # *.ipr
361
+
362
+ # CMake
363
+ cmake-build-*/
364
+
365
+ # Mongo Explorer plugin
366
+ .idea/**/mongoSettings.xml
367
+
368
+ # File-based project format
369
+ *.iws
370
+
371
+ # IntelliJ
372
+ out/
373
+
374
+ # mpeltonen/sbt-idea plugin
375
+ .idea_modules/
376
+
377
+ # JIRA plugin
378
+ atlassian-ide-plugin.xml
379
+
380
+ # Cursive Clojure plugin
381
+ .idea/replstate.xml
382
+
383
+ # SonarLint plugin
384
+ .idea/sonarlint/
385
+
386
+ # Crashlytics plugin (for Android Studio and IntelliJ)
387
+ com_crashlytics_export_strings.xml
388
+ crashlytics.properties
389
+ crashlytics-build.properties
390
+ fabric.properties
391
+
392
+ # Editor-based Rest Client
393
+ .idea/httpRequests
394
+
395
+ # Android studio 3.1+ serialized cache file
396
+ .idea/caches/build_file_checksums.ser
397
+
398
+ ### macOS template
399
+ # General
400
+ .DS_Store
401
+ .AppleDouble
402
+ .LSOverride
403
+
404
+ # Icon must end with two \r
405
+ Icon
406
+
407
+ # Thumbnails
408
+ ._*
409
+
410
+ # Files that might appear in the root of a volume
411
+ .DocumentRevisions-V100
412
+ .fseventsd
413
+ .Spotlight-V100
414
+ .TemporaryItems
415
+ .Trashes
416
+ .VolumeIcon.icns
417
+ .com.apple.timemachine.donotpresent
418
+
419
+ # Directories potentially created on remote AFP share
420
+ .AppleDB
421
+ .AppleDesktop
422
+ Network Trash Folder
423
+ Temporary Items
424
+ .apdisk
425
+
426
+ ### PyCharm+all template
427
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
428
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
429
+
430
+ # User-specific stuff
431
+ .idea/**/workspace.xml
432
+ .idea/**/tasks.xml
433
+ .idea/**/usage.statistics.xml
434
+ .idea/**/dictionaries
435
+ .idea/**/shelf
436
+
437
+ # AWS User-specific
438
+ .idea/**/aws.xml
439
+
440
+ # Generated files
441
+ .idea/**/contentModel.xml
442
+
443
+ # Sensitive or high-churn files
444
+ .idea/**/dataSources/
445
+ .idea/**/dataSources.ids
446
+ .idea/**/dataSources.local.xml
447
+ .idea/**/sqlDataSources.xml
448
+ .idea/**/dynamic.xml
449
+ .idea/**/uiDesigner.xml
450
+ .idea/**/dbnavigator.xml
451
+
452
+ # Gradle
453
+ .idea/**/gradle.xml
454
+ .idea/**/libraries
455
+
456
+ # Gradle and Maven with auto-import
457
+ # When using Gradle or Maven with auto-import, you should exclude module files,
458
+ # since they will be recreated, and may cause churn. Uncomment if using
459
+ # auto-import.
460
+ # .idea/artifacts
461
+ # .idea/compiler.xml
462
+ # .idea/jarRepositories.xml
463
+ # .idea/modules.xml
464
+ # .idea/*.iml
465
+ # .idea/modules
466
+ # *.iml
467
+ # *.ipr
468
+
469
+ # CMake
470
+ cmake-build-*/
471
+
472
+ # Mongo Explorer plugin
473
+ .idea/**/mongoSettings.xml
474
+
475
+ # File-based project format
476
+ *.iws
477
+
478
+ # IntelliJ
479
+ out/
480
+
481
+ # mpeltonen/sbt-idea plugin
482
+ .idea_modules/
483
+
484
+ # JIRA plugin
485
+ atlassian-ide-plugin.xml
486
+
487
+ # Cursive Clojure plugin
488
+ .idea/replstate.xml
489
+
490
+ # SonarLint plugin
491
+ .idea/sonarlint/
492
+
493
+ # Crashlytics plugin (for Android Studio and IntelliJ)
494
+ com_crashlytics_export_strings.xml
495
+ crashlytics.properties
496
+ crashlytics-build.properties
497
+ fabric.properties
498
+
499
+ # Editor-based Rest Client
500
+ .idea/httpRequests
501
+
502
+ # Android studio 3.1+ serialized cache file
503
+ .idea/caches/build_file_checksums.ser
504
+
.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # 默认忽略的文件
2
+ /shelf/
3
+ /workspace.xml
4
+ # 基于编辑器的 HTTP 客户端请求
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
.idea/eDriveMORL.iml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Black">
4
+ <option name="sdkName" value="offlineRLEM" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="offlineRLEM" project-jdk-type="Python SDK" />
7
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/eDriveMORL.iml" filepath="$PROJECT_DIR$/.idea/eDriveMORL.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
CLTC-P-PartI.csv ADDED
@@ -0,0 +1,676 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Time,Speed
2
+ 0,0.0
3
+ 1,0.0
4
+ 2,0.0
5
+ 3,0.0
6
+ 4,0.0
7
+ 5,0.0
8
+ 6,0.0
9
+ 7,0.0
10
+ 8,0.0
11
+ 9,0.0
12
+ 10,0.0
13
+ 11,0.0
14
+ 12,0.0
15
+ 13,0.0
16
+ 14,0.0
17
+ 15,3.2
18
+ 16,5.4
19
+ 17,8.5
20
+ 18,11.5
21
+ 19,14.1
22
+ 20,16.2
23
+ 21,18.7
24
+ 22,19.9
25
+ 23,19.0
26
+ 24,20.6
27
+ 25,20.7
28
+ 26,24.1
29
+ 27,25.8
30
+ 28,27.4
31
+ 29,28.9
32
+ 30,30.1
33
+ 31,31.3
34
+ 32,31.2
35
+ 33,31.2
36
+ 34,32.3
37
+ 35,33.3
38
+ 36,33.4
39
+ 37,33.6
40
+ 38,33.4
41
+ 39,33.3
42
+ 40,33.1
43
+ 41,33.3
44
+ 42,33.5
45
+ 43,33.0
46
+ 44,32.8
47
+ 45,32.6
48
+ 46,32.7
49
+ 47,32.3
50
+ 48,31.9
51
+ 49,31.3
52
+ 50,30.8
53
+ 51,30.6
54
+ 52,29.9
55
+ 53,29.1
56
+ 54,27.0
57
+ 55,25.0
58
+ 56,22.8
59
+ 57,22.1
60
+ 58,21.3
61
+ 59,20.3
62
+ 60,21.2
63
+ 61,22.2
64
+ 62,21.6
65
+ 63,22.1
66
+ 64,23.2
67
+ 65,23.8
68
+ 66,23.2
69
+ 67,22.1
70
+ 68,21.2
71
+ 69,20.0
72
+ 70,18.3
73
+ 71,15.0
74
+ 72,10.0
75
+ 73,5.7
76
+ 74,2.1
77
+ 75,0.0
78
+ 76,0.0
79
+ 77,0.0
80
+ 78,0.0
81
+ 79,0.0
82
+ 80,0.0
83
+ 81,0.0
84
+ 82,0.0
85
+ 83,0.0
86
+ 84,0.0
87
+ 85,0.0
88
+ 86,0.0
89
+ 87,0.0
90
+ 88,0.0
91
+ 89,0.0
92
+ 90,0.0
93
+ 91,0.0
94
+ 92,0.0
95
+ 93,0.0
96
+ 94,0.0
97
+ 95,0.0
98
+ 96,0.0
99
+ 97,0.0
100
+ 98,0.0
101
+ 99,0.0
102
+ 100,0.0
103
+ 101,0.0
104
+ 102,1.4
105
+ 103,2.9
106
+ 104,4.2
107
+ 105,5.3
108
+ 106,6.4
109
+ 107,7.6
110
+ 108,8.7
111
+ 109,9.7
112
+ 110,10.9
113
+ 111,11.8
114
+ 112,12.3
115
+ 113,13.1
116
+ 114,14.7
117
+ 115,16.9
118
+ 116,18.9
119
+ 117,20.2
120
+ 118,20.7
121
+ 119,20.8
122
+ 120,20.6
123
+ 121,19.9
124
+ 122,19.3
125
+ 123,19.1
126
+ 124,19.3
127
+ 125,19.9
128
+ 126,20.9
129
+ 127,22.0
130
+ 128,23.2
131
+ 129,24.3
132
+ 130,25.5
133
+ 131,26.4
134
+ 132,26.9
135
+ 133,27.0
136
+ 134,26.8
137
+ 135,26.6
138
+ 136,26.5
139
+ 137,26.6
140
+ 138,27.0
141
+ 139,27.5
142
+ 140,27.8
143
+ 141,27.6
144
+ 142,26.6
145
+ 143,25.2
146
+ 144,23.6
147
+ 145,22.1
148
+ 146,20.6
149
+ 147,19.3
150
+ 148,18.7
151
+ 149,18.7
152
+ 150,19.1
153
+ 151,19.5
154
+ 152,19.5
155
+ 153,18.9
156
+ 154,17.7
157
+ 155,16.5
158
+ 156,15.7
159
+ 157,15.5
160
+ 158,15.5
161
+ 159,15.6
162
+ 160,16.0
163
+ 161,17.0
164
+ 162,17.9
165
+ 163,18.3
166
+ 164,18.0
167
+ 165,17.1
168
+ 166,15.4
169
+ 167,13.5
170
+ 168,12.0
171
+ 169,11.1
172
+ 170,10.6
173
+ 171,10.5
174
+ 172,10.8
175
+ 173,11.2
176
+ 174,11.4
177
+ 175,11.5
178
+ 176,11.9
179
+ 177,12.4
180
+ 178,13.0
181
+ 179,13.5
182
+ 180,13.7
183
+ 181,13.8
184
+ 182,13.7
185
+ 183,13.3
186
+ 184,12.4
187
+ 185,11.4
188
+ 186,10.6
189
+ 187,10.4
190
+ 188,10.5
191
+ 189,10.9
192
+ 190,11.6
193
+ 191,12.4
194
+ 192,12.9
195
+ 193,13.2
196
+ 194,13.4
197
+ 195,13.5
198
+ 196,13.6
199
+ 197,13.6
200
+ 198,13.5
201
+ 199,13.5
202
+ 200,13.5
203
+ 201,14.0
204
+ 202,15.2
205
+ 203,16.5
206
+ 204,17.3
207
+ 205,17.6
208
+ 206,17.6
209
+ 207,17.5
210
+ 208,17.0
211
+ 209,16.3
212
+ 210,15.5
213
+ 211,14.2
214
+ 212,12.7
215
+ 213,11.4
216
+ 214,10.7
217
+ 215,10.4
218
+ 216,10.5
219
+ 217,10.9
220
+ 218,11.6
221
+ 219,12.0
222
+ 220,12.1
223
+ 221,12.2
224
+ 222,13.0
225
+ 223,15.2
226
+ 224,18.2
227
+ 225,21.0
228
+ 226,23.1
229
+ 227,24.3
230
+ 228,24.6
231
+ 229,24.8
232
+ 230,25.2
233
+ 231,26.2
234
+ 232,27.5
235
+ 233,28.5
236
+ 234,29.0
237
+ 235,29.3
238
+ 236,29.4
239
+ 237,29.2
240
+ 238,28.7
241
+ 239,27.9
242
+ 240,26.8
243
+ 241,25.1
244
+ 242,23.2
245
+ 243,21.2
246
+ 244,18.5
247
+ 245,14.9
248
+ 246,11.6
249
+ 247,9.1
250
+ 248,7.0
251
+ 249,5.6
252
+ 250,4.8
253
+ 251,4.1
254
+ 252,3.3
255
+ 253,2.5
256
+ 254,1.5
257
+ 255,0.0
258
+ 256,0.0
259
+ 257,0.0
260
+ 258,0.0
261
+ 259,0.0
262
+ 260,0.0
263
+ 261,0.0
264
+ 262,0.0
265
+ 263,0.0
266
+ 264,0.0
267
+ 265,0.0
268
+ 266,0.0
269
+ 267,0.0
270
+ 268,0.0
271
+ 269,0.0
272
+ 270,0.0
273
+ 271,0.0
274
+ 272,0.0
275
+ 273,0.0
276
+ 274,1.1
277
+ 275,3.2
278
+ 276,5.5
279
+ 277,7.8
280
+ 278,9.3
281
+ 279,9.6
282
+ 280,10.4
283
+ 281,11.3
284
+ 282,11.4
285
+ 283,9.8
286
+ 284,9.6
287
+ 285,7.1
288
+ 286,5.5
289
+ 287,4.0
290
+ 288,0.7
291
+ 289,0.0
292
+ 290,0.0
293
+ 291,0.0
294
+ 292,0.0
295
+ 293,0.0
296
+ 294,0.0
297
+ 295,0.0
298
+ 296,0.0
299
+ 297,0.0
300
+ 298,0.0
301
+ 299,0.0
302
+ 300,0.0
303
+ 301,0.0
304
+ 302,0.0
305
+ 303,0.0
306
+ 304,0.0
307
+ 305,0.0
308
+ 306,0.0
309
+ 307,0.0
310
+ 308,0.0
311
+ 309,0.0
312
+ 310,0.0
313
+ 311,0.0
314
+ 312,0.0
315
+ 313,0.0
316
+ 314,0.0
317
+ 315,0.0
318
+ 316,0.0
319
+ 317,0.0
320
+ 318,0.0
321
+ 319,0.0
322
+ 320,0.0
323
+ 321,0.0
324
+ 322,0.0
325
+ 323,0.0
326
+ 324,0.0
327
+ 325,3.6
328
+ 326,6.2
329
+ 327,9.7
330
+ 328,11.0
331
+ 329,12.2
332
+ 330,12.5
333
+ 331,12.6
334
+ 332,12.5
335
+ 333,11.6
336
+ 334,10.3
337
+ 335,8.8
338
+ 336,8.3
339
+ 337,7.4
340
+ 338,6.6
341
+ 339,6.8
342
+ 340,8.1
343
+ 341,10.1
344
+ 342,10.6
345
+ 343,10.4
346
+ 344,10.0
347
+ 345,9.4
348
+ 346,8.6
349
+ 347,5.7
350
+ 348,4.6
351
+ 349,0.0
352
+ 350,0.0
353
+ 351,0.0
354
+ 352,0.0
355
+ 353,0.0
356
+ 354,0.0
357
+ 355,0.0
358
+ 356,0.0
359
+ 357,0.0
360
+ 358,0.0
361
+ 359,0.0
362
+ 360,0.0
363
+ 361,0.0
364
+ 362,0.0
365
+ 363,0.0
366
+ 364,0.0
367
+ 365,0.0
368
+ 366,0.0
369
+ 367,0.0
370
+ 368,0.0
371
+ 369,0.0
372
+ 370,0.0
373
+ 371,0.0
374
+ 372,0.0
375
+ 373,0.0
376
+ 374,0.0
377
+ 375,0.0
378
+ 376,0.0
379
+ 377,0.0
380
+ 378,0.0
381
+ 379,0.0
382
+ 380,0.0
383
+ 381,0.0
384
+ 382,0.0
385
+ 383,0.0
386
+ 384,0.0
387
+ 385,0.0
388
+ 386,0.0
389
+ 387,0.0
390
+ 388,0.0
391
+ 389,0.0
392
+ 390,0.0
393
+ 391,0.0
394
+ 392,0.0
395
+ 393,0.0
396
+ 394,0.0
397
+ 395,0.0
398
+ 396,0.0
399
+ 397,0.0
400
+ 398,0.0
401
+ 399,0.0
402
+ 400,0.0
403
+ 401,2.0
404
+ 402,4.0
405
+ 403,5.7
406
+ 404,7.5
407
+ 405,8.8
408
+ 406,9.2
409
+ 407,10.9
410
+ 408,11.8
411
+ 409,12.6
412
+ 410,13.5
413
+ 411,14.0
414
+ 412,14.6
415
+ 413,15.3
416
+ 414,16.2
417
+ 415,16.8
418
+ 416,17.1
419
+ 417,17.5
420
+ 418,17.5
421
+ 419,17.6
422
+ 420,17.0
423
+ 421,15.1
424
+ 422,13.3
425
+ 423,11.8
426
+ 424,10.6
427
+ 425,9.6
428
+ 426,8.6
429
+ 427,7.1
430
+ 428,5.8
431
+ 429,4.9
432
+ 430,3.9
433
+ 431,6.3
434
+ 432,4.6
435
+ 433,2.1
436
+ 434,0.0
437
+ 435,0.0
438
+ 436,0.0
439
+ 437,0.0
440
+ 438,0.0
441
+ 439,0.0
442
+ 440,0.0
443
+ 441,0.0
444
+ 442,0.0
445
+ 443,0.0
446
+ 444,0.0
447
+ 445,0.0
448
+ 446,0.0
449
+ 447,0.0
450
+ 448,0.0
451
+ 449,0.0
452
+ 450,0.0
453
+ 451,0.0
454
+ 452,0.0
455
+ 453,0.0
456
+ 454,0.0
457
+ 455,0.0
458
+ 456,0.0
459
+ 457,0.0
460
+ 458,0.0
461
+ 459,0.0
462
+ 460,0.0
463
+ 461,0.0
464
+ 462,0.0
465
+ 463,0.0
466
+ 464,0.0
467
+ 465,0.0
468
+ 466,0.0
469
+ 467,0.0
470
+ 468,0.0
471
+ 469,0.0
472
+ 470,0.0
473
+ 471,0.0
474
+ 472,0.0
475
+ 473,0.0
476
+ 474,0.0
477
+ 475,0.0
478
+ 476,0.0
479
+ 477,0.0
480
+ 478,0.0
481
+ 479,0.0
482
+ 480,0.0
483
+ 481,0.0
484
+ 482,0.0
485
+ 483,0.0
486
+ 484,0.0
487
+ 485,0.0
488
+ 486,0.0
489
+ 487,0.0
490
+ 488,0.0
491
+ 489,0.0
492
+ 490,0.0
493
+ 491,0.0
494
+ 492,0.0
495
+ 493,0.0
496
+ 494,0.0
497
+ 495,0.0
498
+ 496,0.0
499
+ 497,0.0
500
+ 498,0.0
501
+ 499,0.0
502
+ 500,0.0
503
+ 501,0.0
504
+ 502,0.0
505
+ 503,0.0
506
+ 504,0.0
507
+ 505,0.0
508
+ 506,0.0
509
+ 507,0.0
510
+ 508,0.0
511
+ 509,0.0
512
+ 510,0.0
513
+ 511,0.0
514
+ 512,0.0
515
+ 513,0.0
516
+ 514,0.0
517
+ 515,0.0
518
+ 516,0.0
519
+ 517,0.0
520
+ 518,0.0
521
+ 519,0.0
522
+ 520,5.4
523
+ 521,10.6
524
+ 522,14.5
525
+ 523,15.0
526
+ 524,16.4
527
+ 525,19.7
528
+ 526,24.8
529
+ 527,26.6
530
+ 528,26.1
531
+ 529,27.1
532
+ 530,30.2
533
+ 531,33.5
534
+ 532,34.5
535
+ 533,34.0
536
+ 534,33.5
537
+ 535,34.5
538
+ 536,36.9
539
+ 537,39.2
540
+ 538,41.5
541
+ 539,43.4
542
+ 540,44.4
543
+ 541,45.2
544
+ 542,46.1
545
+ 543,46.1
546
+ 544,45.8
547
+ 545,45.5
548
+ 546,46.1
549
+ 547,46.5
550
+ 548,47.0
551
+ 549,47.5
552
+ 550,48.1
553
+ 551,48.0
554
+ 552,46.8
555
+ 553,46.0
556
+ 554,44.5
557
+ 555,42.0
558
+ 556,39.9
559
+ 557,38.3
560
+ 558,35.5
561
+ 559,31.4
562
+ 560,28.1
563
+ 561,24.1
564
+ 562,18.1
565
+ 563,14.2
566
+ 564,10.5
567
+ 565,6.3
568
+ 566,4.2
569
+ 567,2.9
570
+ 568,1.6
571
+ 569,0.0
572
+ 570,0.0
573
+ 571,0.0
574
+ 572,0.0
575
+ 573,0.0
576
+ 574,0.0
577
+ 575,0.0
578
+ 576,0.0
579
+ 577,0.0
580
+ 578,0.0
581
+ 579,4.3
582
+ 580,6.1
583
+ 581,7.8
584
+ 582,10.8
585
+ 583,14.5
586
+ 584,15.2
587
+ 585,17.4
588
+ 586,20.9
589
+ 587,22.5
590
+ 588,22.5
591
+ 589,22.4
592
+ 590,22.4
593
+ 591,23.3
594
+ 592,23.7
595
+ 593,24.2
596
+ 594,26.9
597
+ 595,30.0
598
+ 596,33.1
599
+ 597,34.1
600
+ 598,34.4
601
+ 599,36.5
602
+ 600,37.5
603
+ 601,37.2
604
+ 602,36.7
605
+ 603,37.2
606
+ 604,37.9
607
+ 605,39.6
608
+ 606,40.0
609
+ 607,41.1
610
+ 608,41.8
611
+ 609,43.2
612
+ 610,43.8
613
+ 611,44.2
614
+ 612,43.9
615
+ 613,44.3
616
+ 614,44.7
617
+ 615,45.2
618
+ 616,44.8
619
+ 617,44.2
620
+ 618,44.2
621
+ 619,44.0
622
+ 620,42.8
623
+ 621,42.7
624
+ 622,43.2
625
+ 623,42.1
626
+ 624,41.5
627
+ 625,40.6
628
+ 626,39.7
629
+ 627,38.5
630
+ 628,37.6
631
+ 629,37.1
632
+ 630,37.1
633
+ 631,37.2
634
+ 632,37.9
635
+ 633,37.8
636
+ 634,36.7
637
+ 635,36.6
638
+ 636,37.2
639
+ 637,36.2
640
+ 638,36.6
641
+ 639,36.1
642
+ 640,35.1
643
+ 641,34.1
644
+ 642,30.9
645
+ 643,23.9
646
+ 644,20.9
647
+ 645,20.4
648
+ 646,19.9
649
+ 647,20.7
650
+ 648,22.8
651
+ 649,25.2
652
+ 650,26.5
653
+ 651,26.4
654
+ 652,25.7
655
+ 653,24.7
656
+ 654,22.6
657
+ 655,20.9
658
+ 656,20.1
659
+ 657,18.7
660
+ 658,16.8
661
+ 659,15.3
662
+ 660,14.3
663
+ 661,13.6
664
+ 662,12.9
665
+ 663,12.2
666
+ 664,11.1
667
+ 665,9.9
668
+ 666,8.1
669
+ 667,5.2
670
+ 668,2.1
671
+ 669,0.0
672
+ 670,0.0
673
+ 671,0.0
674
+ 672,0.0
675
+ 673,0.0
676
+ 674,0.0
datasets/fcev-mpc-v1.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb86b23ecebfe08d3b4c6bb8b188110f3e2c3c2f5dff775c1c7c006ae75679c4
3
+ size 222123046
datasets/fcev-rule-v1.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c92a7991777ca7312b7aff8980dfe64477323f393d1127bf537d58085a679dd2
3
+ size 222119480
fcev.py ADDED
@@ -0,0 +1,494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import numpy as np
4
+ import pandas as pd
5
+ import gymnasium as gym
6
+ from gymnasium.spaces import Box
7
+ from scipy.interpolate import interp1d
8
+ from dataclasses import dataclass, field
9
+
10
+ def load_drive_cycle(path_or_dir):
11
+ """Load a drive cycle from a CSV file or a directory containing CSV files.
12
+
13
+ Args:
14
+ path_or_dir (str): Path to a CSV file or a directory containing CSVs.
15
+
16
+ Returns:
17
+ dict: Dictionary with 'Time' and 'Speed' in SI units (seconds, m/s).
18
+
19
+ Raises:
20
+ ValueError: If no CSV file is found or required columns are missing.
21
+ """
22
+ if os.path.isfile(path_or_dir) and path_or_dir.endswith('.csv'):
23
+ csv_path = path_or_dir
24
+ elif os.path.isdir(path_or_dir):
25
+ # 遍历目录及子目录下所有csv文件
26
+ csv_files = []
27
+ for root, _, files in os.walk(path_or_dir):
28
+ for f in files:
29
+ if f.endswith('.csv'):
30
+ csv_files.append(os.path.join(root, f))
31
+ if not csv_files:
32
+ raise ValueError(f"No CSV file found in directory: {path_or_dir}")
33
+ csv_path = random.choice(csv_files)
34
+ print(f"Randomly selected CSV drive cycle: {csv_path}")
35
+ else:
36
+ raise ValueError(f"Invalid path: {path_or_dir}")
37
+
38
+ df = pd.read_csv(csv_path)
39
+
40
+ if 'Time' not in df.columns or 'Speed' not in df.columns:
41
+ raise ValueError("CSV must contain 'Time' and 'Speed' columns")
42
+
43
+ # Ensure time starts at zero
44
+ time = df['Time'].to_numpy()
45
+ time = time - time[0]
46
+
47
+ return {
48
+ 'Time': time,
49
+ 'Speed': df['Speed'].to_numpy() / 3.6 # Convert km/h to m/s
50
+ }
51
+
52
+
53
+ def fcev_ext(u, w, veh, fd, fc, batt):
54
+ """
55
+ External dynamic model for a fuel cell electric vehicle (FCEV) primarily powered by a fuel cell.
56
+ Supports the main cooling loop with a three-way valve split control structure.
57
+
58
+ Inputs:
59
+ u[0]: Fuel cell output ratio (range: 0 to 1)
60
+ u[1]: Total cooling level (normalized, range: 0.2 to 1.0)
61
+ u[2]: Split ratio to the fuel cell system (FCS) (range: 0 to 1)
62
+ w[0]: Vehicle speed (m/s)
63
+ w[1]: Vehicle acceleration (m/s²)
64
+
65
+ Returns:
66
+ intVar: List of intermediate variables
67
+ unfeas: Infeasibility flag
68
+ """
69
+
70
+ # === Input Processing ===
71
+ v = w[0] # vehicle speed
72
+ a = w[1] # vehicle acceleration
73
+ fc_ratio = u[0] # 燃料电池功率输出比例
74
+ cooling_level = u[1] # 冷却强度 [0.2, 1.0]
75
+ split_ratio = u[2] # 三通阀分流比例 α
76
+
77
+ # === Wheel Dynamics ===
78
+ wheel_spd = v / veh.wh_radius
79
+ wheel_acc = a / veh.wh_radius
80
+
81
+ rolling = veh.mass * veh.gravity * (veh.first_rrc + veh.second_rrc * v)
82
+ aero = veh.aero_coeff * v ** 2
83
+ inertia = veh.mass * a
84
+ veh_force = rolling + aero + inertia
85
+
86
+ wheel_trq = veh_force * veh.wh_radius + veh.axle_loss * (wheel_spd != 0)
87
+
88
+ # === Final Drive ===
89
+ fd_spd = fd.spdRatio * wheel_spd
90
+ fd_trq = wheel_trq / fd.spdRatio + fd.loss * np.sign(wheel_trq)
91
+
92
+ # === Simple Motor Dynamics ===
93
+ shaft_spd = fd_spd
94
+ shaft_trq = fd_trq
95
+ mot_pwr = shaft_spd * shaft_trq
96
+
97
+ # === Fuel Cell Ideal Output ===
98
+ fc_ratio = np.clip(fc_ratio, 0, 1)
99
+ fc_pwr = fc_ratio * fc.maxPwr
100
+ batt_pwr = mot_pwr - fc_pwr
101
+
102
+ # === Fuel Cell Efficiency & Hydrogen Usage ===
103
+ fc_eff = fc.effMap(fc_pwr)
104
+ fc_eff = np.maximum(fc_eff, np.finfo(float).eps)
105
+ h2_rate = fc.h2Map(fc_pwr)
106
+ # print(f"H2 Rate: {h2_rate}, || Fuel Cell Power: {fc_pwr}")
107
+
108
+ # === Cooling System ===
109
+ fc.maxCoolFlow = 0.2 # 假设的最大冷却流速 kg/s
110
+ m_dot_total = cooling_level * fc.maxCoolFlow
111
+
112
+ m_dot_fc = split_ratio * m_dot_total
113
+ m_dot_batt = (1 - split_ratio) * m_dot_total
114
+
115
+ # === Feasibility Check ===
116
+ fc_unfeas = (fc_pwr > fc.maxPwr) | (fc_pwr < fc.minPwr)
117
+ batt_unfeas = (batt_pwr > batt.maxPwr) | (batt_pwr < batt.minPwr)
118
+ unfeas = fc_unfeas | batt_unfeas
119
+
120
+ # === Output Intermediate Variables ===
121
+ intVar = [
122
+ batt_pwr, # 1
123
+ fc_pwr, # 2
124
+ h2_rate, # 3
125
+ np.ones_like(fc_pwr) * shaft_spd, # 4
126
+ m_dot_fc, # 5
127
+ m_dot_batt # 6
128
+ ]
129
+
130
+ return intVar, unfeas
131
+
132
+
133
+ def fcev_int(x, w, u, intVar, batt, fc):
134
+ """
135
+ Internal state update function for a fuel cell electric vehicle (FCEV),
136
+ including thermal and electrical models for both battery and fuel cell.
137
+
138
+ Args:
139
+ x (list[float]): Current state variables:
140
+ x[0]: State of Charge (SOC)
141
+ x[1]: Fuel cell temperature (T_fc)
142
+ x[2]: Battery core temperature (T_core)
143
+ x[3]: Battery surface temperature (T_surf)
144
+ w (Union[list, dict]): External inputs (e.g., vehicle speed/acc) and previous controls if available.
145
+ u (list[float]): Control inputs:
146
+ u[0]: Fuel cell output ratio (0 to 1)
147
+ u[1]: Normalized total cooling level (0.2 to 1.0)
148
+ u[2]: Coolant split ratio to fuel cell (0 to 1)
149
+ intVar (list[float]): Intermediate variables:
150
+ intVar[0]: Battery power
151
+ intVar[1]: Fuel cell power
152
+ intVar[2]: Hydrogen consumption rate
153
+ intVar[4]: Coolant flow rate through fuel cell
154
+ intVar[5]: Coolant flow rate through battery
155
+ batt: Battery model object (with methods like `ocv()`, `chrgRes()`, `dischrgRes()`, etc.)
156
+ fc: Fuel cell model object (with methods like `effMap()` and `heatCap`)
157
+
158
+ Returns:
159
+ tuple:
160
+ x_new (list[float]): Updated state vector [SOC, T_fc, T_core, T_surf]
161
+ stageCost (float): Calculated cost including hydrogen consumption and penalties
162
+ unfeas (bool): Feasibility flag (True if thermal or electrical limits exceeded)
163
+ H2_rate (float): Hydrogen consumption rate
164
+ dT_core (float): Battery core temperature change rate
165
+ dT_fc (float): Fuel cell temperature change rate
166
+ """
167
+ # === Extract state variables ===
168
+ SOC = x[0]
169
+ T_fc = x[1]
170
+ T_core = x[2]
171
+ T_surf = x[3]
172
+
173
+ # === Extract intermediate variables ===
174
+ battPwr = intVar[0]
175
+ fcPwr = intVar[1]
176
+ H2_rate = intVar[2]
177
+ m_dot_fc = intVar[4]
178
+ m_dot_batt = intVar[5]
179
+
180
+ # === Constants ===
181
+ dt = 1.0 # Time step (s)
182
+ T_amb = 20.0 # Ambient temperature (°C)
183
+ cp = 4180.0 # Specific heat capacity of coolant (J/kg°C)
184
+
185
+ # === Battery electrical model ===
186
+ battPwr_adj = np.where(battPwr > 0, battPwr / 0.95, battPwr * 0.95)
187
+ Rbat = np.where(battPwr > 0, batt.dischrgRes(SOC), batt.chrgRes(SOC))
188
+ Vbat = batt.ocv(SOC)
189
+
190
+ sqrt_term = Vbat ** 2 - 4 * Rbat * battPwr_adj
191
+ sqrt_term = np.maximum(sqrt_term, 0)
192
+ Ibatt = (Vbat - np.sqrt(sqrt_term)) / (2 * Rbat)
193
+ Ibatt = np.real(Ibatt)
194
+
195
+ # === SOC update ===
196
+ SOC_new = SOC - Ibatt / (batt.maxCap * 3600) * dt
197
+ battUnfeas = (Ibatt > batt.maxCurr(SOC)) | (Ibatt < batt.minCurr(SOC))
198
+
199
+ # === Fuel Cell Thermal Model ===
200
+ eta_fc = np.maximum(fc.effMap(fcPwr), np.finfo(float).eps)
201
+ Qgen_fc = (1 - eta_fc) * fcPwr
202
+ Qcool_fc = m_dot_fc * cp * (T_fc - T_amb)
203
+ dT_fc = (Qgen_fc - Qcool_fc) / fc.heatCap
204
+ T_fc_new = T_fc + dt * dT_fc
205
+
206
+ # === Battery thermal model ===
207
+ Qgen_batt = Ibatt ** 2 * Rbat
208
+ Rth_in = 0.2
209
+ Ccore = 3000.0
210
+ Csurf = 2000.0
211
+ Qcool_batt = m_dot_batt * cp * (T_surf - T_amb)
212
+
213
+ dT_core = (Qgen_batt - (T_core - T_surf) / Rth_in) / Ccore
214
+ dT_surf = ((T_core - T_surf) / Rth_in - Qcool_batt) / Csurf
215
+
216
+ T_core_new = T_core + dt * dT_core
217
+ T_surf_new = T_surf + dt * dT_surf
218
+
219
+ # === Stage cost calculation ===
220
+ stageCost = H2_rate
221
+
222
+ # Add cooling system power penalty (quadratic)
223
+ m_dot_total = m_dot_fc + m_dot_batt
224
+ stageCost += 1e-3 * m_dot_total ** 2
225
+
226
+ # Add control smoothness penalty (Δu²)
227
+ if isinstance(w, dict) and "u_prev" in w:
228
+ u_prev = w["u_prev"][0] # 之前的fcRatio
229
+ fcRatio = u[0]
230
+ delta_u = fcRatio - u_prev
231
+ stageCost += 1e-4 * delta_u ** 2
232
+
233
+ # === Temperature feasibility check (hard constraint) ===
234
+ T_ref_fc = 60.0
235
+ T_th_fc = 80.0
236
+ k_fc = 8.0
237
+
238
+ # --- Battery degradation penalty ---
239
+ T_ref_batt = 35.0
240
+ T_th_batt = 45.0
241
+ k_batt = 6.0
242
+ if T_core >= 100 or T_fc >= 100:
243
+ T_core = np.clip(T_core, 0, 100) # 或 120 上限
244
+ T_fc = np.clip(T_fc, 0, 100)
245
+ TempUnfeas = True
246
+ else:
247
+ TempUnfeas = False
248
+
249
+ # === Lifetime degradation penalties (soft constraint) ===
250
+
251
+ # Fuel cell degradation penalty
252
+ fc_life_penalty = np.where(
253
+ T_fc > T_th_fc,
254
+ 1e-2 * np.exp((T_fc - T_ref_fc) / k_fc),
255
+ 0.0
256
+ )
257
+
258
+ # Battery degradation penalty
259
+ batt_life_penalty = np.where(
260
+ T_core > T_th_batt,
261
+ 1e-2 * np.exp((T_core - T_ref_batt) / k_batt),
262
+ 0.0
263
+ )
264
+
265
+
266
+ stageCost += fc_life_penalty + batt_life_penalty
267
+
268
+ # === Output new states ===
269
+ x_new = [
270
+ SOC_new,
271
+ T_fc_new,
272
+ T_core_new,
273
+ T_surf_new
274
+ ]
275
+
276
+ # Combine feasibility flags
277
+ unfeas = battUnfeas or TempUnfeas
278
+
279
+ if unfeas:
280
+ print(battUnfeas, f" {SOC} || {T_core} || {T_surf} || {T_fc} || f{Ibatt} || f{batt.maxCurr(SOC)} || f{batt.minCurr(SOC)}")
281
+
282
+ return x_new, stageCost, unfeas, H2_rate, dT_core, dT_fc
283
+
284
+
285
+ @dataclass
286
+ class Vehicle:
287
+ mass: float = 1920 # kg
288
+ gravity: float = 9.81
289
+ wh_radius: float = 0.32 # m
290
+ first_rrc: float = 0.009
291
+ second_rrc: float = 0.001
292
+ aero_coeff: float = field(init=False)
293
+ axle_loss: float = 100
294
+
295
+ def __post_init__(self):
296
+ Cd = 0.29
297
+ A = 2.3
298
+ rho = 1.225
299
+ self.aero_coeff = 0.5 * Cd * A * rho
300
+
301
+
302
+ @dataclass
303
+ class FinalDrive:
304
+ spdRatio: float = 9.0
305
+ loss: float = 50
306
+
307
+
308
+ @dataclass
309
+ class FuelCell:
310
+ minPwr: float = 0
311
+ maxPwr: float = 114000
312
+ pwrBrk: np.ndarray = field(default_factory=lambda: np.linspace(0, 114000, 20))
313
+ etaBrk: np.ndarray = field(default_factory=lambda: np.array([
314
+ 0.0, 0.25, 0.4, 0.48, 0.53, 0.56, 0.59, 0.6,
315
+ 0.605, 0.61, 0.6, 0.59, 0.58, 0.57, 0.56, 0.54,
316
+ 0.52, 0.5, 0.48, 0.46
317
+ ]))
318
+ thermEff: float = 0.4
319
+ coolingCoeff: float = 40
320
+ heatCap: float = 20000
321
+ effMap: callable = field(init=False)
322
+ h2Map: callable = field(init=False)
323
+
324
+ def __post_init__(self):
325
+ eff_interp = interp1d(self.pwrBrk, self.etaBrk, kind='linear', fill_value='extrapolate')
326
+ self.effMap = lambda P: np.minimum(1, np.maximum(eff_interp(P), np.finfo(float).eps))
327
+
328
+ LHV_H2 = 33.3e6 # J/kg
329
+ self.h2Map = lambda P: 1e3 * P / np.maximum(self.effMap(P) * LHV_H2, np.finfo(float).eps)
330
+
331
+
332
+ @dataclass
333
+ class Battery:
334
+ maxCap: float = 10 # Ah
335
+ minPwr: float = -20000 # W
336
+ maxPwr: float = 25000 # W
337
+ socBrk: np.ndarray = field(default_factory=lambda: np.linspace(0, 1, 11))
338
+ ocvData: np.ndarray = field(init=False)
339
+ chrgResData: np.ndarray = field(init=False)
340
+ dischrgResData: np.ndarray = field(init=False)
341
+ minCurrData: np.ndarray = field(init=False)
342
+ maxCurrData: np.ndarray = field(init=False)
343
+ ocv: callable = field(init=False)
344
+ chrgRes: callable = field(init=False)
345
+ dischrgRes: callable = field(init=False)
346
+ minCurr: callable = field(init=False)
347
+ maxCurr: callable = field(init=False)
348
+ coolingCoeff: float = 10
349
+ heatCap: float = 6000
350
+
351
+ def __post_init__(self):
352
+ self.ocvData = 320 + 20 * self.socBrk
353
+ self.chrgResData = 0.3 - 0.1 * self.socBrk
354
+ self.dischrgResData = 0.2 + 0.05 * (1 - self.socBrk)
355
+ self.minCurrData = -120 + np.zeros_like(self.socBrk)
356
+ self.maxCurrData = 180 + np.zeros_like(self.socBrk)
357
+
358
+ self.ocv = interp1d(self.socBrk, self.ocvData, kind='linear', fill_value='extrapolate')
359
+ self.chrgRes = interp1d(self.socBrk, self.chrgResData, kind='linear', fill_value='extrapolate')
360
+ self.dischrgRes = interp1d(self.socBrk, self.dischrgResData, kind='linear', fill_value='extrapolate')
361
+ self.minCurr = interp1d(self.socBrk, self.minCurrData, kind='linear', fill_value='extrapolate')
362
+ self.maxCurr = interp1d(self.socBrk, self.maxCurrData, kind='linear', fill_value='extrapolate')
363
+
364
+
365
+ def fcev_fcdom_data():
366
+ veh = Vehicle()
367
+ fd = FinalDrive()
368
+ fc = FuelCell()
369
+ batt = Battery()
370
+ return veh, fd, fc, batt
371
+
372
+ def reward_function(stage_cost, speed, beta=0.01, c=10):
373
+ if stage_cost == 0 and speed == 0:
374
+ return 0.0
375
+ return 1 / (1 + np.exp(beta * (stage_cost - c)))
376
+
377
+ class FCEVEnv(gym.Env):
378
+ """
379
+ Custom OpenAI Gym environment for a fuel cell electric vehicle (FCEV) with
380
+ thermal-electric hybrid modeling. The environment simulates internal vehicle
381
+ dynamics and evaluates control actions based on energy efficiency and constraints.
382
+
383
+ Observations:
384
+ [vehicle_speed, acceleration, SOC, T_fc, T_core, T_surf]
385
+
386
+ Actions:
387
+ [fuel_cell_output_ratio (0~1), cooling_level (0.2~1.0), coolant_split_ratio (0~1)]
388
+
389
+ Reward:
390
+ Based on custom reward function applied to stage cost.
391
+ """
392
+ def __init__(self, drive_cycle):
393
+ super(FCEVEnv, self).__init__()
394
+ self.dt = 1.0
395
+
396
+ # Load vehicle, powertrain, battery, and fuel cell parameters
397
+ self.veh, self.fd, self.fc, self.batt = fcev_fcdom_data()
398
+
399
+ # Load and interpolate driving cycle to match simulation timestep
400
+ self.speed_profile = np.interp(
401
+ np.arange(0, drive_cycle['Time'][-1] + 1),
402
+ drive_cycle['Time'] - drive_cycle['Time'][0],
403
+ drive_cycle['Speed']
404
+ )
405
+ self.steps = len(self.speed_profile)
406
+ self.step_count = 0
407
+
408
+ # Obs Space:[SOC, T_fc, T_core, T_surf, speed, acceleration]
409
+ self.observation_space = Box(low=np.array([-np.inf, -np.inf, -np.inf, -np.inf, -np.inf, -np.inf]),
410
+ high=np.array([np.inf, np.inf, np.inf, np.inf, np.inf, np.inf]),
411
+ dtype=np.float32)
412
+
413
+ # Act Space:[fc_ratio, cooling_level, split_ratio]
414
+ self.action_space = Box(low=np.array([0, 0, 0]),
415
+ high=np.array([1.0, 1.0, 1.0]),
416
+ dtype=np.float32)
417
+
418
+ self.reset()
419
+
420
+ def reset(self):
421
+ """Reset the simulation to initial state."""
422
+ self.state = [0.5, 25, 25, 25] # [SOC, T_fc, T_core, T_surf]
423
+ self.step_count = 0
424
+ return self._get_obs(), None
425
+
426
+ def _get_obs(self):
427
+ """Get the current observation including vehicle dynamics and system state."""
428
+ speed = self.speed_profile[self.step_count] if self.step_count < self.steps else self.speed_profile[self.step_count - 1]
429
+ if self.step_count + 1 < self.steps:
430
+ next_speed = self.speed_profile[self.step_count + 1]
431
+ else:
432
+ next_speed = self.speed_profile[self.step_count]
433
+ acc = (next_speed - speed) / self.dt
434
+ return np.array([speed, acc] + self.state, dtype=np.float32)
435
+
436
+ def step(self, action):
437
+ """
438
+ Apply a control action and update the environment state.
439
+
440
+ Args:
441
+ action (list or ndarray): Action input [fc_ratio, cooling_level, split_ratio]
442
+
443
+ Returns:
444
+ tuple: (observation, reward, done, unfeasible_flag, info_dict)
445
+ """
446
+ u = [float(a) for a in action]
447
+ speed = self.speed_profile[self.step_count]
448
+ if self.step_count + 1 < self.steps:
449
+ next_speed = self.speed_profile[self.step_count + 1]
450
+ else:
451
+ next_speed = self.speed_profile[self.step_count]
452
+
453
+ acc = (next_speed - speed) / self.dt
454
+
455
+ w = [speed, acc]
456
+
457
+ # 执行外部动力学
458
+ intVar, _ = fcev_ext(u, w, self.veh, self.fd, self.fc, self.batt)
459
+
460
+ # 内部状态更新
461
+ x_new, stageCost, unfeas, h2_rate, dT_core, dT_fc = fcev_int(self.state, w, u, intVar, self.batt, self.fc)
462
+
463
+ self.state = x_new
464
+ self.step_count += 1
465
+ done = self.step_count >= self.steps - 1 or unfeas
466
+ # print(f"{self.step_count >= self.steps} or {unfeas}")
467
+ obs = self._get_obs()
468
+ reward = reward_function(stageCost, speed) if not unfeas else -99
469
+
470
+
471
+ return obs, reward, done, unfeas, {"H2_rate": h2_rate * self.dt, "dT_core": dT_core * self.dt, "dT_fc": dT_fc * self.dt}
472
+
473
+ def render(self, mode='human'):
474
+ """Render the current step's state to console."""
475
+ print(f"Step {self.step_count}, State: {self.state}")
476
+
477
+ def get_logs(self):
478
+ """Return final state and step count for logging."""
479
+ return {
480
+ "final_state": self.state,
481
+ "step_count": self.step_count
482
+ }
483
+
484
+
485
+ if __name__ == '__main__':
486
+ veh, fd, fc, batt = fcev_fcdom_data()
487
+
488
+ # Demo
489
+ P_test = np.array([0, 20000, 60000, 110000])
490
+ eff = fc.effMap(P_test)
491
+ h2 = fc.h2Map(P_test)
492
+
493
+ print("H2 Efficiency:", eff)
494
+ print("Hydrogen Consumption (g/s):", h2)
minari_export/minari_MPC/data/dataset.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c254a21cdea0faab1838e21ce9986839abc978d67a85f78ec5af712161bf60c
3
+ size 1798380054
minari_export/minari_MPC/dataset_info.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dataset_id": "minari_MPC",
3
+ "env_id": "FCEV-SimulatedEnv-v0",
4
+ "total_episodes": 9197,
5
+ "total_steps": 5.194267E+6,
6
+ "observation_dimension": 6,
7
+ "action_dimension": 3,
8
+ "reward_range": [
9
+ 1.0000000000000003E-5,
10
+ 513.01058735562515
11
+ ],
12
+ "creation_date": "2025-04-15 22:24:19",
13
+ "author": "Your Name or Lab",
14
+ "strategy_type": "MPC"
15
+ }
minari_export/minari_Rule/data/dataset.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88c821505a70c2518b6cb4251498953e5d631aeb65079e5cf3540384a928a712
3
+ size 1946797994
minari_export/minari_Rule/dataset_info.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dataset_id": "minari_Rule",
3
+ "env_id": "FCEV-SimulatedEnv-v0",
4
+ "total_episodes": 9197,
5
+ "total_steps": 5.194267E+6,
6
+ "observation_dimension": 6,
7
+ "action_dimension": 3,
8
+ "reward_range": [
9
+ 1.8567978538054825E-6,
10
+ 2002.4124479044558
11
+ ],
12
+ "creation_date": "2025-04-15 22:30:42",
13
+ "author": "Your Name or Lab",
14
+ "strategy_type": "Rule"
15
+ }
register_minari_dataset.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import numpy as np
4
+ import gymnasium as gym
5
+ from gymnasium.spaces import Box
6
+ import minari
7
+ from minari.data_collector import EpisodeBuffer
8
+ from minari import create_dataset_from_buffers
9
+ from gymnasium.envs.registration import EnvSpec
10
+ from numpy import dtype
11
+ from fcev import FCEVEnv, load_drive_cycle
12
+
13
+ def reward_function(stage_cost, state, beta=0.01, c=10):
14
+ """Custom reward function based on stage cost and system state.
15
+
16
+ Args:
17
+ stage_cost (float): Original stage cost.
18
+ state (np.ndarray): Observation state.
19
+ beta (float): Slope parameter for logistic transformation.
20
+ c (float): Cost offset threshold.
21
+
22
+ Returns:
23
+ float: Transformed reward value.
24
+ """
25
+ if stage_cost == 0 and state[0] == 0:
26
+ return 0.0
27
+ return 1 / (1 + np.exp(beta * (stage_cost - c)))
28
+
29
+
30
+ def load_matlab_json_data(json_path):
31
+ with open(json_path, 'r') as f:
32
+ data = json.load(f)
33
+
34
+ episodes = dict()
35
+
36
+ for t in data:
37
+ eid = t.get("episode_id", 0)
38
+ if eid not in episodes:
39
+ episodes[eid] = {
40
+ "observations": [],
41
+ "actions": [],
42
+ "rewards": [],
43
+ "next_observations": [],
44
+ "terminations": [],
45
+ }
46
+ episodes[eid]["observations"].append(t["observation"])
47
+ episodes[eid]["actions"].append(t["action"])
48
+ episodes[eid]["rewards"].append(reward_function(stage_cost=t["reward"],state=t["observation"]))
49
+ episodes[eid]["next_observations"].append(t["next_observation"])
50
+ episodes[eid]["terminations"].append(t["termination"])
51
+
52
+ for epi in episodes.keys():
53
+ episodes[epi]["observations"] = np.array(episodes[epi]["observations"], dtype=np.float32)
54
+ episodes[epi]["actions"] = np.array(episodes[epi]["actions"], dtype=np.float32)
55
+ episodes[epi]["rewards"] = np.array(episodes[epi]["rewards"], dtype=np.float32)
56
+ if np.isnan(episodes[epi]["rewards"]).any():
57
+ print("Detected NaN, in episode", eid)
58
+ episodes[epi]["rewards"] = np.nan_to_num(episodes[epi]["rewards"], nan=0)
59
+ episodes[epi]["next_observations"] = np.array(episodes[epi]["next_observations"], dtype=np.float32)
60
+ episodes[epi]["terminations"] = np.array(episodes[epi]["terminations"], dtype=np.bool)
61
+
62
+ return episodes
63
+
64
+
65
+ def register_minari_dataset(folder_path, dataset_id):
66
+ dataset_json_path = os.path.join(folder_path, 'data', 'dataset.json')
67
+ info_json_path = os.path.join(folder_path, 'dataset_info.json')
68
+
69
+ # load data from json
70
+ episodes = load_matlab_json_data(dataset_json_path)
71
+
72
+ with open(info_json_path, 'r') as f:
73
+ info = json.load(f)
74
+
75
+ # example_ep = episodes[1]
76
+ # obs_dim = example_ep["observations"].shape[1]
77
+ # act_dim = example_ep["actions"].shape[1]
78
+ #
79
+ # observation_space = Box(-np.inf, np.inf, shape=(obs_dim,), dtype=np.float32)
80
+ # action_space = Box(0.0, 1.0, shape=(act_dim,), dtype=np.float32)
81
+ #
82
+ # class DummyEnv(gym.Env):
83
+ # def __init__(self):
84
+ # self.observation_space = observation_space
85
+ # self.action_space = action_space
86
+ # self.spec = EnvSpec(id="FCEV-SimulatedEnv-v0")
87
+ #
88
+ # env = DummyEnv()
89
+ env = FCEVEnv(load_drive_cycle("CLTC-P-PartI.csv"))
90
+
91
+ buffers = []
92
+
93
+ xid = 0
94
+
95
+ for eid, ep in episodes.items():
96
+ obs = ep["observations"]
97
+ next_obs = ep["next_observations"]
98
+ actions = ep["actions"]
99
+ rewards = ep["rewards"]
100
+ rewards = np.clip(rewards, -1e6, 1e6)
101
+ terminations =ep["terminations"]
102
+ truncations = np.zeros_like(terminations, dtype=bool)
103
+
104
+ full_obs = np.vstack([obs, next_obs[-1:]]) # 末尾补 observation
105
+
106
+ buffer = EpisodeBuffer(
107
+ id=xid,
108
+ observations=full_obs,
109
+ actions=actions,
110
+ rewards=rewards,
111
+ terminations=terminations,
112
+ truncations=truncations,
113
+ )
114
+ buffers.append(buffer)
115
+ xid += 1
116
+
117
+ dataset = create_dataset_from_buffers(
118
+ dataset_id=dataset_id,
119
+ env=env,
120
+ buffer=buffers,
121
+ algorithm_name=info.get("strategy_type", "unknown"),
122
+ author=info.get("author", "matlab-export"),
123
+ )
124
+
125
+ print(f"✅ Minari dataset formed:{dataset_id}")
126
+ return dataset
127
+
128
+
129
+ if __name__ == "__main__":
130
+ base_dir = "minari_export"
131
+ strategies = ["mpc", "rule"]
132
+
133
+ for strat in strategies:
134
+ folder = os.path.join(base_dir, f"minari_{strat}")
135
+ dataset_id = f"fcev-{strat}-v1"
136
+ try:
137
+ minari.delete_dataset(dataset_id)
138
+ except:
139
+ pass
140
+ register_minari_dataset(folder, dataset_id)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ wandb~=0.19.9
2
+ d3rlpy~=2.8.1
3
+ numpy~=2.0.2
4
+ pandas~=2.2.3
5
+ gymnasium~=1.0.0
6
+ scipy~=1.13.1
7
+ minari~=0.5.2
run.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import wandb
2
+ import d3rlpy
3
+ import argparse
4
+ import traceback
5
+
6
+ from d3rlpy.dataset import ReplayBuffer, InfiniteBuffer
7
+ from d3rlpy.preprocessing import StandardObservationScaler
8
+ from d3rlpy.logging import CombineAdapterFactory, FileAdapterFactory, TensorboardAdapterFactory
9
+ from fcev import FCEVEnv, load_drive_cycle
10
+ from d3rlpy.algos import (
11
+ TD3PlusBCConfig, IQLConfig, CQLConfig, BCQConfig,
12
+ CalQLConfig, AWACConfig, ReBRACConfig, TACRConfig,
13
+ PLASConfig, PRDCConfig, BEARConfig
14
+ )
15
+
16
+ from typing import Any, Optional
17
+ from d3rlpy.logging import WanDBAdapter
18
+ from d3rlpy.logging.logger import (
19
+ AlgProtocol,
20
+ LoggerAdapter,
21
+ LoggerAdapterFactory,
22
+ SaveProtocol,
23
+ )
24
+
25
+ # ---------- WandB Logger Factory ----------
26
+ class GWanDBAdapterFactory(LoggerAdapterFactory):
27
+ r"""WandB Logger Adapter Factory class.
28
+
29
+ This class creates instances of the WandB Logger Adapter for experiment
30
+ tracking.
31
+
32
+ Args:
33
+ project (Optional[str], optional): The name of the WandB project.
34
+ Defaults to None.
35
+ """
36
+
37
+ _project: Optional[str]
38
+
39
+ def __init__(self, project: Optional[str] = None, experiment_name: Optional[str] = None,) -> None:
40
+ self._project = project
41
+
42
+ def create(
43
+ self, algo: AlgProtocol, experiment_name: str, n_steps_per_epoch: int
44
+ ) -> LoggerAdapter:
45
+ return WanDBAdapter(
46
+ algo=algo,
47
+ experiment_name=experiment_name,
48
+ n_steps_per_epoch=n_steps_per_epoch,
49
+ project=self._project,
50
+ )
51
+
52
+
53
+
54
+ # ---------- Algorithm Config Dictionary ----------
55
+ def get_algo_configs():
56
+ # Algorithm configurations with encoder and observation preprocessing settings
57
+ algo_configs = {
58
+ "TD3PlusBC": TD3PlusBCConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
59
+ "IQL": IQLConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
60
+ "CQL": CQLConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
61
+ "BCQ": BCQConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
62
+ "CalQL": CalQLConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
63
+ "AWAC": AWACConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
64
+ "ReBRAC": ReBRACConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), q_func_factory=d3rlpy.models.QRQFunctionFactory()),
65
+ "TACR": TACRConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
66
+ "PLAS": PLASConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
67
+ "PRDC": PRDCConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
68
+ "BEAR": BEARConfig(actor_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), critic_encoder_factory=d3rlpy.models.DefaultEncoderFactory(use_batch_norm=True, dropout_rate=0.2), observation_scaler=StandardObservationScaler()),
69
+ }
70
+ return algo_configs
71
+
72
+ # ---------- Training Function ----------
73
+ def train(args):
74
+ algo_configs = get_algo_configs()
75
+
76
+ if args.algo not in algo_configs:
77
+ raise ValueError(f"Unsupported algorithm: {args.algo}")
78
+
79
+ # Load dataset
80
+ with open(args.dataset_path, "rb") as f:
81
+ dataset = ReplayBuffer.load(f, InfiniteBuffer())
82
+
83
+ # Load environment for evaluation
84
+ env = FCEVEnv(load_drive_cycle(args.drive_cycle))
85
+
86
+ config = algo_configs[args.algo]
87
+ algo = config.create(device=args.device)
88
+
89
+ # Setup logger
90
+ logger_adapters = [
91
+ FileAdapterFactory(root_dir=f"d3rlpy_logs/{args.algo}"),
92
+ TensorboardAdapterFactory(root_dir=f"tensorboard_logs/{args.algo}")
93
+ ]
94
+ if args.wandb:
95
+ logger_adapters.append(GWanDBAdapterFactory(experiment_name=f"{args.algo}-run", project=args.wandb_project))
96
+
97
+ logger_adapter = CombineAdapterFactory(logger_adapters)
98
+
99
+ try:
100
+ print(f"\n🚀 Starting training: {args.algo}")
101
+
102
+ algo.fit(
103
+ dataset,
104
+ n_steps=args.n_steps,
105
+ n_steps_per_epoch=args.n_steps_per_epoch,
106
+ logger_adapter=logger_adapter,
107
+ evaluators={
108
+ 'init_value': d3rlpy.metrics.InitialStateValueEstimationEvaluator(),
109
+ 'soft_opc': d3rlpy.metrics.SoftOPCEvaluator(return_threshold=100),
110
+ 'action': d3rlpy.metrics.ContinuousActionDiffEvaluator(),
111
+ 'environment': d3rlpy.metrics.EnvironmentEvaluator(env),
112
+ 'Advantage': d3rlpy.metrics.DiscountedSumOfAdvantageEvaluator()
113
+ },
114
+ )
115
+
116
+ print(f"\n✅ Training finished for: {args.algo}")
117
+
118
+ except Exception as e:
119
+ print(f"\n❌ Training failed: {args.algo}")
120
+ print(traceback.format_exc())
121
+ wandb.finish()
122
+
123
+
124
+ # ---------- Main CLI ----------
125
+ if __name__ == "__main__":
126
+ parser = argparse.ArgumentParser(description="Offline RL training for FCEV")
127
+
128
+ parser.add_argument("--algo", type=str, default="AWAC",
129
+ choices=list(get_algo_configs().keys()),
130
+ help="Name of the offline RL algorithm")
131
+ parser.add_argument("--dataset-path", type=str, default="datasets/fcev-mpc-v1.h5",
132
+ help="Path to the .h5 dataset file")
133
+ parser.add_argument("--drive-cycle", type=str, default="CLTC-P-PartI.csv",
134
+ help="Path to the drive cycle CSV file")
135
+ parser.add_argument("--n-steps", type=int, default=10000,
136
+ help="Total number of training steps")
137
+ parser.add_argument("--n-steps-per-epoch", type=int, default=100,
138
+ help="Steps per epoch")
139
+ parser.add_argument("--device", type=str, default="cuda:0",
140
+ help="Training device (e.g., 'cpu', 'cuda:0')")
141
+ parser.add_argument("--wandb", action="store_true",
142
+ help="Enable WandB logging")
143
+ parser.add_argument("--wandb-project", type=str, default="fcev-offline-benchmark",
144
+ help="WandB project name (used only if --wandb is enabled)")
145
+
146
+ args = parser.parse_args()
147
+ train(args)
train.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import minari
2
+ import numpy as np
3
+ import d3rlpy.dataset
4
+ from d3rlpy.dataset import MDPDataset
5
+ from fcev import FCEVEnv, load_drive_cycle
6
+ from d3rlpy.algos import SACConfig, TD3PlusBCConfig, IQLConfig, CQLConfig, BCQConfig, CalQLConfig, AWACConfig, \
7
+ ReBRACConfig, TACRConfig, PLASConfig, PRDCConfig, BEARConfig, DecisionTransformerConfig, CalQL
8
+
9
+ def load_minari_as_d3rlpy(name="fcev-mpc-v1", num=None):
10
+ """Load Minari dataset with a custom reward function.
11
+
12
+ Args:
13
+ name (str): Dataset name.
14
+ num (int, optional): Number of episodes to sample.
15
+ beta (float): Logistic function slope.
16
+ c (float): Offset for logistic transformation.
17
+
18
+ Returns:
19
+ MDPDataset: Dataset with custom rewards.
20
+ """
21
+ dataset = minari.load_dataset(name)
22
+ episodes = dataset.sample_episodes(num) if num else dataset.sample_episodes(dataset.total_episodes)
23
+
24
+ all_obs = []
25
+ all_actions = []
26
+ all_rewards = []
27
+ all_terminals = []
28
+
29
+ for ep in episodes:
30
+ obs = ep.observations[:-1]
31
+ actions = ep.actions
32
+ rewards = ep.rewards
33
+ terminals = ep.terminations
34
+
35
+ n = len(actions)
36
+ obs = obs[:n]
37
+ actions = actions[:n]
38
+ rewards = rewards[:n]
39
+ terminals = terminals[:n]
40
+
41
+ all_obs.append(obs)
42
+ all_actions.append(actions)
43
+ all_rewards.append(rewards)
44
+ all_terminals.append(terminals)
45
+
46
+ obs = np.vstack(all_obs)
47
+ act = np.vstack(all_actions)
48
+ reward = np.hstack(all_rewards)
49
+ terminal = np.hstack(all_terminals)
50
+
51
+ return MDPDataset(
52
+ observations=obs,
53
+ actions=act,
54
+ rewards=reward,
55
+ terminals=terminal
56
+ )
57
+
58
+
59
+ # Define environment and dataset
60
+ env_name = "fcev-mpc-v1"
61
+ # env_name = "fcev-rule-v1"
62
+
63
+ # Save dataset to disk
64
+ dataset = load_minari_as_d3rlpy(env_name)
65
+
66
+ # Reload dataset using ReplayBuffer
67
+ dataset.dump(f"datasets/{env_name}.h5")
68
+ with open(f"datasets/{env_name}.h5", "rb") as f:
69
+ dataset = d3rlpy.dataset.ReplayBuffer.load(f, d3rlpy.dataset.InfiniteBuffer())
70
+ # dataset = d3rlpy.datasets.get_minari("fcev-mpc-v1")
71
+
72
+ # Select and build algorithm
73
+ # algo = SACConfig(compile_graph=True).create()
74
+ # algo = TD3PlusBCConfig(compile_graph=True).create()
75
+ algo = CQLConfig(compile_graph=True).create()
76
+ # algo = BCQConfig(compile_graph=True).create()
77
+ # algo = IQLConfig(compile_graph=True).create()
78
+ # algo = CalQLConfig(compile_graph=True).create()
79
+ # algo = DecisionTransformerConfig(compile_graph=True).create()
80
+
81
+ # Setup logging
82
+ algo.build_with_env(env=FCEVEnv(load_drive_cycle("CLTC-P-PartI.csv")))
83
+
84
+ # Setup FileAdapterFactory and TensorboardAdapterFactory
85
+ logger_adapter = d3rlpy.logging.CombineAdapterFactory([
86
+ d3rlpy.logging.FileAdapterFactory(root_dir="d3rlpy_logs"),
87
+ d3rlpy.logging.TensorboardAdapterFactory(root_dir="tensorboard_logs"),
88
+ d3rlpy.logging.WanDBAdapterFactory()
89
+ ])
90
+
91
+ # Train the algorithm offline
92
+ algo.fit(dataset, n_steps=10000, n_steps_per_epoch=1000)
93
+ # algo = TD3PlusBC(actor_learning_rate=1e-4, alpha=2.5)
94
+ # algo.fit(dataset, n_epochs=200)
95
+ # algo.save_model("td3bc_model.d3")