MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
GymCollection.cs
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Reflection;
7using System.Text;
8using System.Threading.Tasks;
9
10namespace MyCaffe.gym
11{
15 public class GymCollection : IEnumerable<IXMyCaffeGym>
16 {
17 List<IXMyCaffeGym> m_rgGym = new List<IXMyCaffeGym>();
18
23 {
24 }
25
34 public List<Exception> Load()
35 {
36 m_rgGym.Add(new CartPoleGym());
37 m_rgGym.Add(new AtariGym());
38 m_rgGym.Add(new CurveGym());
39 m_rgGym.Add(new DataGeneralGym());
40 m_rgGym.Add(new ModelGym());
41
42 return addCustomGyms();
43 }
44
45 private List<Exception> addCustomGyms()
46 {
47 string codeBase = Assembly.GetExecutingAssembly().CodeBase;
48 UriBuilder uri = new UriBuilder(codeBase);
49 string path = Uri.UnescapeDataString(uri.Path);
50 string strPath = Path.GetDirectoryName(path);
51 List<Exception> rgErr = new List<Exception>();
52
53 strPath += "\\CustomGyms";
54
55 if (Directory.Exists(strPath))
56 {
57 string[] rgstrFiles = Directory.GetFiles(strPath);
58
59 foreach (string strFile in rgstrFiles)
60 {
61 FileInfo fi = new FileInfo(strFile);
62
63 if (fi.Extension.ToLower() == ".dll")
64 {
65 Exception excpt;
66 IXMyCaffeGym igym = loadCustomGym(strFile, out excpt);
67 if (igym != null)
68 {
69 m_rgGym.Add(igym);
70 }
71 else if (excpt != null)
72 {
73 rgErr.Add(excpt);
74 }
75 }
76 }
77 }
78
79 return rgErr;
80 }
81
82 private IXMyCaffeGym loadCustomGym(string strFile, out Exception err)
83 {
84 err = null;
85
86 try
87 {
88 Assembly a = Assembly.LoadFile(strFile);
89 AssemblyName aName = a.GetName();
90
91 foreach (Type t in a.GetTypes())
92 {
93 Type[] rgT = t.GetInterfaces();
94
95 foreach (Type iface in rgT)
96 {
97 string strIface = iface.ToString();
98 if (strIface.Contains("IXMyCaffeGym"))
99 {
100 object obj = Activator.CreateInstance(t);
101 return obj as IXMyCaffeGym;
102 }
103 }
104 }
105
106 return null;
107 }
108 catch (Exception excpt)
109 {
110 if (excpt is System.Reflection.ReflectionTypeLoadException)
111 {
112 var typeLoadException = excpt as ReflectionTypeLoadException;
113 var loaderExceptions = typeLoadException.LoaderExceptions;
114
115 if (loaderExceptions != null && loaderExceptions.Length > 0)
116 excpt = new Exception("Gym '" + strFile + "' failed to load!", loaderExceptions[0]);
117 }
118
119 err = excpt;
120
121 return null;
122 }
123 }
124
130 public IXMyCaffeGym Find(string strName)
131 {
132 int nPos = strName.IndexOf(':');
133 if (nPos > 0)
134 strName = strName.Substring(0, nPos);
135
136 foreach (IXMyCaffeGym igym in m_rgGym)
137 {
138 if (igym.Name == strName)
139 return igym;
140 }
141
142 return null;
143 }
144
149 public IEnumerator<IXMyCaffeGym> GetEnumerator()
150 {
151 return m_rgGym.GetEnumerator();
152 }
153
158 IEnumerator IEnumerable.GetEnumerator()
159 {
160 return m_rgGym.GetEnumerator();
161 }
162 }
163}
The Atari Gym provides acess to the Atari-2600 Emulator from Stella (https://github....
Definition: AtariGym.cs:42
The CartPole Gym provides a simulation of a cart with a balancing pole standing on top of it.
Definition: CartPoleGym.cs:27
The Curve Gym provides a simulation of continuous curve such as Sin or Cos.
Definition: CurveGym.cs:19
The DataGeneral Gym provides access to the MyCaffe Streaming Database with GENERAL query types.
The GymCollection contains the available Gyms.
GymCollection()
The constructor.
List< Exception > Load()
Loads the default and dynamic gyms.
IXMyCaffeGym Find(string strName)
Search for a given Gym by its name.
IEnumerator< IXMyCaffeGym > GetEnumerator()
Returns the collections enumerator.
The Model Gym runs a given Project over the dataset specified within the project where each step adva...
Definition: ModelGym.cs:29
The IXMyCaffeGym interface is used to interact with each Gym.
Definition: Interfaces.cs:99
string Name
Returns the name of the gym.
Definition: Interfaces.cs:119
The MyCaffe.gym namespace contains all classes related to the Gym's supported by MyCaffe.