-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
68 lines (62 loc) · 2.4 KB
/
Program.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
using System;
using Newtonsoft.Json;
using System.IO;
using ScottPlot;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
KLerning kLerning = new KLerning(30, 4);
var (converged, episodes) = kLerning.Train();
Console.WriteLine($"Converged: {converged}, Episodes: {episodes}");
// Pfad für die JSON- und PNG-Datei
string jsonPath = Path.Combine(Directory.GetCurrentDirectory(), "rewardsPerEpisode.json");
string imagePath = Path.Combine(Directory.GetCurrentDirectory(), "Q-Learning.png");
// Speichern der Belohnungen pro Episode in eine JSON-Datei
try
{
File.WriteAllText(jsonPath, JsonConvert.SerializeObject(kLerning.RewardsPerEpisode));
Console.WriteLine("Belohnungen wurden in " + jsonPath + " gespeichert.");
}
catch (Exception ex)
{
Console.WriteLine("Fehler beim Schreiben der JSON-Datei: " + ex.Message);
}
// Erstellen und Speichern des Plots
try
{
var plt = new ScottPlot.Plot(600, 400);
plt.AddScatter(DataGen.Consecutive(kLerning.RewardsPerEpisode.Count), kLerning.RewardsPerEpisode.ToArray());
plt.Title("Q-Learning Fortschritt");
plt.XLabel("Episoden");
plt.YLabel("Belohnung");
plt.SaveFig(imagePath);
Console.WriteLine("Plot gespeichert als: " + imagePath);
}
catch (Exception ex)
{
Console.WriteLine("Fehler beim Erstellen des Plots: " + ex.Message);
}
try
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "python"; // oder "python3", je nach Systemkonfiguration
start.Arguments = "plot_data.py"; // Pfad zum Python-Skript
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using(Process process = Process.Start(start))
{
using(StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.WriteLine(result);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Fehler beim Starten des Python-Skripts: " + ex.Message);
}
}
}