Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get install -y g++ cmake libboost-all-dev libgtest-dev libeigen3-dev
sudo apt-get install -y g++ cmake libboost-all-dev libgtest-dev libeigen3-dev libblas-dev
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ INCLUDE_DIRECTORIES(src/)

FILE(GLOB SRCS src/rlenvs/*.cpp
src/rlenvs/api_server/*.cpp
src/rlenvs/detail/*.cpp
src/rlenvs/envs/*.cpp
src/rlenvs/envs/gymnasium/*.cpp
src/rlenvs/envs/gymnasium/toy_text/*.cpp
src/rlenvs/envs/gymnasium/classic_control/*.cpp
src/rlenvs/envs/gymnasium/classic_control/vector/*.cpp
src/rlenvs/envs/gdrl/*.cpp
src/rlenvs/envs/gym_pybullet_drones/*.cpp
#src/rlenvs/envs/gym_pybullet_drones/*.cpp
src/rlenvs/envs/grid_world/*.cpp
src/rlenvs/envs/connect2/*.cpp
src/rlenvs/dynamics/*.cpp
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LINK_DIRECTORIES(${CMAKE_INSTALL_PREFIX})
ADD_SUBDIRECTORY(example_1)
ADD_SUBDIRECTORY(example_2)
ADD_SUBDIRECTORY(example_3)
ADD_SUBDIRECTORY(example_4)
#ADD_SUBDIRECTORY(example_4)
ADD_SUBDIRECTORY(example_5)
ADD_SUBDIRECTORY(example_6)
ADD_SUBDIRECTORY(example_7)
Expand Down
63 changes: 54 additions & 9 deletions examples/example_1/example_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void test_frozen_lake(){

// make the environment
std::unordered_map<std::string, std::any> options;
options.insert({"is_slippery", true});
options.insert({"is_slippery", false});
env.make("v1", options);

std::cout<<"Is environment created? "<<env.is_created()<<std::endl;
Expand All @@ -40,7 +40,8 @@ void test_frozen_lake(){
std::cout<<time_step<<std::endl;

// take an action in the environment
auto new_time_step = env.step(rlenvscpp::envs::gymnasium::FrozenLakeActionsEnum::RIGHT);
// 2 = RIGHT
auto new_time_step = env.step(2);

std::cout<<new_time_step<<std::endl;

Expand All @@ -58,9 +59,22 @@ void test_frozen_lake(){
std::cout<<std::get<2>(item)<<std::endl;
std::cout<<std::get<3>(item)<<std::endl;
}

action = env.sample_action();
new_time_step = env.step(action);

std::cout<<new_time_step<<std::endl;

// synchronize the environment
env.sync(std::unordered_map<std::string, std::any>());

auto copy_env = env.make_copy(1);
copy_env.reset();

std::cout<<"Org env cidx: "<<env.cidx()<<std::endl;
std::cout<<"Copy env cidx: "<<copy_env.cidx()<<std::endl;

copy_env.close();

// close the environment
env.close();
Expand All @@ -81,7 +95,8 @@ void test_taxi(){
std::cout<<"Is environment alive? "<<env.is_alive()<<std::endl;
std::cout<<"Number of valid actions? "<<env.n_actions()<<std::endl;
std::cout<<"Number of states? "<<env.n_states()<<std::endl;



// reset the environment
auto time_step = env.reset(42, std::unordered_map<std::string, std::any>());

Expand All @@ -93,7 +108,8 @@ void test_taxi(){
std::cout<<time_step<<std::endl;

// take an action in the environment
auto new_time_step = env.step(rlenvscpp::envs::gymnasium::TaxiActionsEnum::RIGHT);
// move RIGHT
auto new_time_step = env.step(2);

std::cout<<new_time_step<<std::endl;

Expand All @@ -111,10 +127,21 @@ void test_taxi(){
std::cout<<std::get<2>(item)<<std::endl;
std::cout<<std::get<3>(item)<<std::endl;
}



auto copy_env_1 = env.make_copy(1);
copy_env_1.reset();

auto copy_env_2 = env.make_copy(2);
copy_env_2.reset();
std::cout<<"Org env cidx: "<<env.cidx()<<std::endl;
std::cout<<"Copy env 1 cidx: "<<copy_env_1.cidx()<<std::endl;
std::cout<<"Copy env 2 cidx: "<<copy_env_2.cidx()<<std::endl;

// close the environment
env.close();

copy_env_2.close();
copy_env_1.close();
}


Expand All @@ -131,14 +158,24 @@ void test_black_jack(){
auto state = env.reset();

std::cout<<"Environment step..."<<std::endl;
env.step(rlenvscpp::envs::gymnasium::BlackJackActionsEnum::HIT);
env.step(rlenvscpp::envs::gymnasium::BlackJackActionsEnum::STICK);

// 0 = HIT
// 1 = STICK
env.step(0);
env.step(1);

// synchronize the environment
env.sync(std::unordered_map<std::string, std::any>());

auto copy_env = env.make_copy(1);
copy_env.reset();

std::cout<<"Org env cidx: "<<env.cidx()<<std::endl;
std::cout<<"Copy env cidx: "<<copy_env.cidx()<<std::endl;

// close the environment
env.close();
copy_env.close();

}

Expand Down Expand Up @@ -170,7 +207,8 @@ void test_cliff_world(){
std::cout<<time_step<<std::endl;

// take an action in the environment
auto new_time_step = env.step(rlenvscpp::envs::gymnasium::CliffWorldActionsEnum::UP);
// 0 = UP
auto new_time_step = env.step(0);

std::cout<<new_time_step<<std::endl;

Expand All @@ -192,8 +230,15 @@ void test_cliff_world(){
// synchronize the environment
env.sync(std::unordered_map<std::string, std::any>());

auto copy_env = env.make_copy(1);
copy_env.reset();

std::cout<<"Org env cidx: "<<env.cidx()<<std::endl;
std::cout<<"Copy env cidx: "<<copy_env.cidx()<<std::endl;

// close the environment
env.close();
copy_env.close();

}

Expand Down
10 changes: 6 additions & 4 deletions examples/example_5/example_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ namespace example_5{
rlenvscpp::envs::grid_world::Gridworld<4> env;

std::unordered_map<std::string, std::any> options;
options["mode"] = std::any(rlenvscpp::envs::grid_world::to_string(rlenvscpp::envs::grid_world::GridWorldInitType::STATIC));
options["mode"] = std::any(GridWorldInitType::STATIC);

env.make("v0", options);

std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
std::cout<<"Number of states: "<<env.n_states()<<std::endl;

std::cout<<"Version: "<<env.version()<<std::endl;
std::cout<<"Name: "<<env.env_name()<<std::endl;
env.close();
}

Expand All @@ -42,13 +43,14 @@ namespace example_5{
rlenvscpp::envs::grid_world::Gridworld<4> env;

std::unordered_map<std::string, std::any> options;
options["mode"] = std::any(rlenvscpp::envs::grid_world::to_string(rlenvscpp::envs::grid_world::GridWorldInitType::RANDOM));
options["mode"] = std::any(GridWorldInitType::RANDOM);

env.make("v0", options);

std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;
std::cout<<"Number of states: "<<env.n_states()<<std::endl;

std::cout<<"Version: "<<env.version()<<std::endl;
std::cout<<"Name: "<<env.env_name()<<std::endl;
env.close();
}

Expand Down
3 changes: 2 additions & 1 deletion examples/example_6/example_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ int main(){
std::cout<<"Number of actions: "<<env.n_actions()<<std::endl;

// make the environment
env.make("v1");
std::unordered_map<std::string, std::any> options;
env.make("v1", options);

auto time_step = env.reset();

Expand Down
Loading
Loading