Skip to content

Commit 617517c

Browse files
committed
Remove obsolete code
1 parent 75e2254 commit 617517c

File tree

6 files changed

+52
-320
lines changed

6 files changed

+52
-320
lines changed

examples/example_6/example_6.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

2-
//#include "bitrl/envs/gymnasium/classic_control/pendulum_env.h"
3-
//#include "bitrl/envs/gymnasium/classic_control/vector/acrobot_vec_env.h"
2+
#include "bitrl/envs/gymnasium/classic_control/pendulum_env.h"
43
#include "bitrl/envs/gymnasium/classic_control/cart_pole_env.h"
54
#include "bitrl/network/rest_rl_env_client.h"
65
#include "bitrl/bitrl_types.h"
@@ -48,33 +47,34 @@ namespace example
4847

4948
env.close();
5049
}
51-
// void test_pendulum(RESTRLEnvClient& server)
52-
// {
53-
//
54-
// // the environment is not registered with the server
55-
// std::cout<<"Is environment registered: "<<server.is_env_registered(Pendulum::name)<<std::endl;
56-
//
57-
// // create the environment
58-
// Pendulum env(server);
59-
//
60-
// std::cout<<"Name: "<<env.name<<std::endl;
61-
// std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
62-
//
63-
// // make the environment
64-
// std::unordered_map<std::string, std::any> options;
65-
// std::unordered_map<std::string, std::any> reset_ops;
66-
// reset_ops.insert({"seed", static_cast<uint_t>(42)});
67-
// env.make("v1", options, reset_ops);
68-
//
69-
// auto time_step = env.reset();
70-
// std::cout<<"Time step: "<<time_step<<std::endl;
71-
//
72-
// // step in the environment
73-
// time_step = env.step(0.0);
74-
// std::cout<<"Time step after action: "<<time_step<<std::endl;
75-
//
76-
// env.close();
77-
// }
50+
51+
void test_pendulum(RESTRLEnvClient& server)
52+
{
53+
54+
// the environment is not registered with the server
55+
std::cout<<"Is environment registered: "<<server.is_env_registered(Pendulum::name)<<std::endl;
56+
57+
// create the environment
58+
Pendulum env(server);
59+
60+
std::cout<<"Name: "<<env.name<<std::endl;
61+
std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
62+
63+
// make the environment
64+
std::unordered_map<std::string, std::any> options;
65+
std::unordered_map<std::string, std::any> reset_ops;
66+
reset_ops.insert({"seed", static_cast<uint_t>(42)});
67+
env.make("v1", options, reset_ops);
68+
69+
auto time_step = env.reset();
70+
std::cout<<"Time step: "<<time_step<<std::endl;
71+
72+
// step in the environment
73+
time_step = env.step(0.0);
74+
std::cout<<"Time step after action: "<<time_step<<std::endl;
75+
76+
env.close();
77+
}
7878

7979
}
8080

@@ -87,11 +87,11 @@ int main(){
8787

8888
RESTRLEnvClient server(SERVER_URL, true);
8989

90-
std::cout<<"Testing FrozenLake..."<<std::endl;
90+
std::cout<<"Testing CartPole..."<<std::endl;
9191
example::test_cart_pole(server);
9292
std::cout<<"===================="<<std::endl;
93-
std::cout<<"Testing Taxi..."<<std::endl;
94-
//example::test_pendulum(server);
93+
std::cout<<"Testing Pendulum..."<<std::endl;
94+
example::test_pendulum(server);
9595
std::cout<<"===================="<<std::endl;
9696
// std::cout<<"Testing BlackJack..."<<std::endl;
9797
// example_1::test_black_jack(server);

src/bitrl/envs/env_base.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#ifndef ENV_BASE_H
22
#define ENV_BASE_H
33

4-
///
5-
/// \file env_base.h
6-
///
74
#include "bitrl/bitrl_types.h"
85
#include "bitrl/bitrl_consts.h"
9-
#include "bitrl/envs/synchronized_env_mixin.h"
106

117
#include <unordered_map>
128
#include <any>
@@ -30,7 +26,7 @@ namespace envs{
3026
* state and action space definitions
3127
*/
3228
template<typename TimeStepType, typename SpaceType>
33-
class EnvBase: public SpaceType, public synchronized_env_mixin
29+
class EnvBase: public SpaceType
3430
{
3531
public:
3632

@@ -197,7 +193,6 @@ template<typename TimeStepType, typename SpaceType>
197193
EnvBase<TimeStepType, SpaceType>::EnvBase(const std::string& idx, const std::string& name)
198194
:
199195
SpaceType(),
200-
synchronized_env_mixin(),
201196
is_created_(false),
202197
idx_(idx),
203198
version_(),
@@ -209,7 +204,6 @@ template<typename TimeStepType, typename SpaceType>
209204
EnvBase<TimeStepType, SpaceType>::EnvBase(const EnvBase<TimeStepType, SpaceType>& other)
210205
:
211206
SpaceType(),
212-
synchronized_env_mixin(),
213207
is_created_(other.is_created_),
214208
idx_(other.idx_),
215209
version_(other.version_),

src/bitrl/envs/env_types.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifndef BITRL_ENV_TYPES_H
2+
#define BITRL_ENV_TYPES_H
13
#include "bitrl/bitrl_types.h"
24
#include "bitrl/envs/space_type.h"
35

@@ -223,4 +225,6 @@ struct DiscreteVectorStateDiscreteActionEnv
223225
};
224226

225227
}
226-
}
228+
}
229+
230+
#endif

src/bitrl/envs/space_type.h

Lines changed: 1 addition & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,7 @@ struct ContinuousScalareSpace
127127
static constexpr uint_t size = Size;
128128
};
129129

130-
///
131-
/// \brief A space that represents a range of discrete
132-
///
133-
template<real_t S, real_t E>
134-
struct BoundedContinuousScalarSpace
135-
{
136-
///
137-
/// \brief item_t
138-
///
139-
typedef real_t space_item_type;
140-
141-
///
142-
/// \brief The overall size of the space meaning
143-
/// how many elements can potentially the space have
144-
///
145-
static constexpr uint_t size = 1;
146-
147-
///
148-
/// \brief The boundaries the scalar value can assume
149-
///
150-
static constexpr RealRange<S, E> limits = RealRange<S, E>();
151-
};
130+
152131

153132

154133
template<uint_t Size, typename T=real_t>
@@ -168,227 +147,6 @@ struct ContinuousVectorSpace
168147
typedef std::vector<T> space_item_type;
169148
};
170149

171-
172-
173-
174-
175-
/*template<uint_t SpaceSize>
176-
typename DiscreteSpace<SpaceSize>::space_item_type
177-
DiscreteSpace<SpaceSize>::sample(uint_t seed){
178-
179-
std::uniform_int_distribution<> dist(0, SpaceSize - 1);
180-
std::mt19937 gen(seed);
181-
return dist(gen);
182-
}
183-
184-
template<uint_t SpaceSize>
185-
std::vector<typename DiscreteSpace<SpaceSize>::space_item_type>
186-
DiscreteSpace<SpaceSize>::sample(uint_t seed, uint_t size){
187-
188-
std::vector<typename DiscreteSpace<SpaceSize>::space_item_type> vals_;
189-
vals_.reserve(size);
190-
191-
std::uniform_int_distribution<> dist(0, SpaceSize - 1);
192-
std::mt19937 gen(seed);
193-
for(uint_t i=0; i<size; ++i){
194-
195-
vals_.push_back(dist(gen));
196-
}
197-
198-
return vals_;
199-
}*/
200-
201-
/*
202-
template<typename T=real_t>
203-
struct ScalarContinuousSpace
204-
{
205-
static_assert(std::is_floating_point_v<T> == true && "Floating point type is expected");
206-
207-
///
208-
/// \brief item_t
209-
///
210-
typedef T space_item_type;
211-
212-
213-
///
214-
/// \brief size
215-
///
216-
static constexpr uint_t size = 1;
217-
218-
};
219-
220-
///
221-
/// \brief Discrete vector space all elements of the
222-
/// space should be of integral type. A discrete vector
223-
/// can be used to specify a discrete state that is vector
224-
/// valued see e.g. the Connect2 environment
225-
///
226-
template<typename uint_t SpaceSize, typename VectorType>
227-
struct DiscreteVectorSpace;
228-
229-
template<uint_t SpaceSize, typename T=uint_t>
230-
struct DiscreteVectorSpace<SpaceSize, DynVec<T> >
231-
{
232-
static_assert(std::is_integral_v<T> == true && "Integral type is expected");
233-
234-
///
235-
/// \brief item_t
236-
///
237-
typedef std::vector<T> space_item_type;
238-
239-
240-
///
241-
/// \brief size
242-
///
243-
static constexpr uint_t size = SpaceSize;
244-
245-
///
246-
/// \brief sample
247-
/// \return
248-
///
249-
static space_item_type sample();
250-
251-
///
252-
/// \brief sample
253-
/// \param seed
254-
/// \return
255-
///
256-
static space_item_type sample(uint_t seed);
257-
258-
///
259-
/// \brief sample
260-
/// \param seed
261-
/// \return
262-
///
263-
static std::vector<space_item_type> sample(uint_t seed, uint_t size);
264-
};
265-
266-
267-
template<uint_t SpaceSize, typename T=uint_t>
268-
struct DiscreteVectorSpace<SpaceSize, std::vector<T> >
269-
{
270-
271-
static_assert(std::is_integral_v<T> == true && "Integral type is expected");
272-
273-
///
274-
/// \brief item_t
275-
///
276-
typedef std::vector<T> space_item_type;
277-
278-
279-
///
280-
/// \brief size
281-
///
282-
static constexpr uint_t size = SpaceSize;
283-
284-
///
285-
/// \brief sample
286-
/// \return
287-
///
288-
static space_item_type sample();
289-
290-
///
291-
/// \brief sample
292-
/// \param seed
293-
/// \return
294-
///
295-
static space_item_type sample(uint_t seed);
296-
297-
///
298-
/// \brief sample
299-
/// \param seed
300-
/// \return
301-
///
302-
static std::vector<space_item_type> sample(uint_t seed, uint_t size);
303-
};
304-
305-
template<uint_t SpaceSize>
306-
typename DiscreteSpace<SpaceSize>::space_item_type
307-
DiscreteSpace<SpaceSize>::sample(){
308-
309-
std::uniform_int_distribution<> dist(0, SpaceSize - 1);
310-
std::random_device rd;
311-
std::mt19937 gen(rd());
312-
return dist(gen);
313-
}
314-
315-
template<uint_t SpaceSize>
316-
typename DiscreteSpace<SpaceSize>::space_item_type
317-
DiscreteSpace<SpaceSize>::sample(uint_t seed){
318-
319-
std::uniform_int_distribution<> dist(0, SpaceSize - 1);
320-
std::mt19937 gen(seed);
321-
return dist(gen);
322-
}
323-
324-
template<uint_t SpaceSize>
325-
std::vector<typename DiscreteSpace<SpaceSize>::space_item_type>
326-
DiscreteSpace<SpaceSize>::sample(uint_t seed, uint_t size){
327-
328-
std::vector<typename DiscreteSpace<SpaceSize>::space_item_type> vals_;
329-
vals_.reserve(size);
330-
331-
std::uniform_int_distribution<> dist(0, SpaceSize - 1);
332-
std::mt19937 gen(seed);
333-
for(uint_t i=0; i<size; ++i){
334-
335-
vals_.push_back(dist(gen));
336-
}
337-
338-
return vals_;
339-
}
340-
341-
template<uint_t SpaceSize, typename ItemType = std::vector<real_t>>
342-
struct ContinuousSpace{
343-
344-
///
345-
/// \brief item_t
346-
///
347-
typedef std::vector<real_t> space_item_type;
348-
349-
///
350-
/// \brief size. The number of members in the space
351-
///
352-
static constexpr uint_t size = SpaceSize;
353-
};
354-
355-
///
356-
/// \brief The ContinuousSpace class.
357-
///
358-
//template<uint_t SpaceSize>
359-
//struct ContinuousSpace<SpaceSize, std::vector<real_t> >
360-
//{
361-
// ///
362-
// /// \brief item_t
363-
// ///
364-
// typedef std::vector<real_t> space_item_type;
365-
//
366-
// ///
367-
// /// \brief size. The number of members in the space
368-
// ///
369-
// static constexpr uint_t size = SpaceSize;
370-
//
371-
//};
372-
373-
374-
375-
template<>
376-
struct ContinuousSpace<1, Null>
377-
{
378-
379-
///
380-
/// \brief item_t
381-
///
382-
typedef real_t space_item_type;
383-
384-
///
385-
/// \brief size. The number of members in the space
386-
///
387-
static constexpr uint_t size = 1;
388-
389-
};
390-
*/
391-
392150
template<uint_t SpaceSize, typename T=uint_t>
393151
struct DiscreteVectorSpace
394152
{

0 commit comments

Comments
 (0)