Skip to content

Commit

Permalink
the algorithm work. but, we need to add method to check the terminal …
Browse files Browse the repository at this point in the history
…tree. Moreover, the name of the blocking save impact the execution. Need to fix it
  • Loading branch information
Alphadius committed Jan 16, 2024
1 parent e65aa0f commit 5ffaab5
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 57 deletions.
4 changes: 2 additions & 2 deletions blocking/inc/gmds/blocking/CurvedBlocking.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct CellInfo
* @param AGeomDim on-classify geometric cell dimension (4 if not classified)
* @param AGeomId on-classify geometric cell unique id
*/
CellInfo(cad::GeomManager* AManager, const int ATopoDim = 4, const int AGeomDim = 4, const int AGeomId = NullID) :
CellInfo(cad::GeomManager* AManager=NULL, const int ATopoDim = 4, const int AGeomDim = 4, const int AGeomId = NullID) :
topo_dim(ATopoDim), topo_id(m_counter_global_id++), geom_manager(AManager),geom_dim(AGeomDim), geom_id(AGeomId)
{
}
Expand All @@ -74,7 +74,7 @@ struct NodeInfo : CellInfo
* @param AGeomId on-classify geometric cell unique id
* @param APoint geometric location
*/
NodeInfo(cad::GeomManager* AManager, const int AGeomDim = 4, const int AGeomId = NullID, const math::Point &APoint = math::Point(0, 0, 0)) :
NodeInfo(cad::GeomManager* AManager=NULL, const int AGeomDim = 4, const int AGeomId = NullID, const math::Point &APoint = math::Point(0, 0, 0)) :
CellInfo(AManager, 0, AGeomDim, AGeomId), point(APoint)
{
}
Expand Down
81 changes: 81 additions & 0 deletions blocking/tst/ExecutionActionsTestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,84 @@ TEST(ExecutionActionsTestSuite,cb5){
vtk_writer_edges.write("debug_blocking_edges.vtk");
}



TEST(ExecutionActionsTestSuite,cb2_auto) {
gmds::cad::FACManager geom_model;
set_up_file(&geom_model,"cb2.vtk");
gmds::blocking::CurvedBlocking bl(&geom_model,true);
gmds::blocking::CurvedBlockingClassifier classifier(&bl);


classifier.clear_classification();

auto errors = classifier.classify();


//Check nb points of the geometry and nb nodes of the blocking
ASSERT_EQ(16,geom_model.getNbPoints());
ASSERT_EQ(24,geom_model.getNbCurves());
ASSERT_EQ(10,geom_model.getNbSurfaces());
ASSERT_EQ(8,bl.get_all_nodes().size());
ASSERT_EQ(12,bl.get_all_edges().size());
ASSERT_EQ(6,bl.get_all_faces().size());



//Check elements class and captured
//Check nb nodes/edges/faces no classified
ASSERT_EQ(0,errors.non_classified_nodes.size());
ASSERT_EQ(0,errors.non_classified_edges.size());
ASSERT_EQ(6,errors.non_classified_faces.size());

//Check nb points/curves/surfaces no captured
ASSERT_EQ(8,errors.non_captured_points.size());
ASSERT_EQ(12,errors.non_captured_curves.size());
ASSERT_EQ(10,errors.non_captured_surfaces.size());

auto listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);


classifier.classify();

listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);

classifier.classify();

listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);

classifier.classify();

listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);


gmds::Mesh m(gmds::MeshModel(gmds::DIM3|gmds::N|gmds::E|gmds::F|gmds::R|gmds::E2N|gmds::F2N|gmds::R2N));
bl.convert_to_mesh(m);


gmds::IGMeshIOService ios(&m);
gmds::VTKWriter vtk_writer(&ios);
vtk_writer.setCellOptions(gmds::N|gmds::R);
vtk_writer.setDataOptions(gmds::N|gmds::R);
vtk_writer.write("cb2_debug_blocking.vtk");
gmds::VTKWriter vtk_writer_edges(&ios);
vtk_writer_edges.setCellOptions(gmds::N|gmds::E);
vtk_writer_edges.setDataOptions(gmds::N|gmds::E);
vtk_writer_edges.write("cb2_debug_blocking_edges.vtk");
gmds::VTKWriter vtk_writer_faces(&ios);
vtk_writer_faces.setCellOptions(gmds::N|gmds::F);
vtk_writer_faces.setDataOptions(gmds::N|gmds::F);
vtk_writer_faces.write("cb2_debug_blocking_faces.vtk");


}


2 changes: 2 additions & 0 deletions rlBlocking/inc/gmds/rlBlocking/MCTSAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define GMDS_MCTSAGENT_H

#include <gmds/rlBlocking/MCTSTree.h>
#include <iostream>
#include <random>
/*----------------------------------------------------------------------------------------*/
namespace gmds {
/*----------------------------------------------------------------------------------------*/
Expand Down
3 changes: 2 additions & 1 deletion rlBlocking/inc/gmds/rlBlocking/MCTSMove.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct LIB_GMDS_RLBLOCKING_API MCTSMove {
/** @brief Overloaded ==
*/
virtual bool operator==(const MCTSMove& AOther) const = 0;
virtual std::string sprint() const { return "Not implemented"; } // and optionally this
virtual std::string sprint() const { return "Not implemented"; }
virtual void print() const =0; // and optionally this
};
/*----------------------------------------------------------------------------*/
}
Expand Down
7 changes: 4 additions & 3 deletions rlBlocking/inc/gmds/rlBlocking/MCTSMovePolycube.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ struct LIB_GMDS_RLBLOCKING_API MCTSMovePolycube: public MCTSMove {
TCellID m_AIdEdge;
TCellID m_AIdBlock;
double m_AParamCut;
/** @brief if typeMove=0: delete block, typeMove=1 cut block
/** @brief if typeMove=2: delete block, typeMove=1 cut block
*/
bool m_typeMove;
unsigned int m_typeMove;

/** @brief Overloaded ==
*/
MCTSMovePolycube(TCellID AIdEdge,TCellID AIdBlock, double AParamCut,bool ATypeMove);
MCTSMovePolycube(TCellID AIdEdge = -1,TCellID AIdBlock = -1 , double AParamCut = 0,unsigned int ATypeMove = -1);
bool operator==(const MCTSMove& AOther) const;
void print() const;

};
/*----------------------------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion rlBlocking/inc/gmds/rlBlocking/MCTSState.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LIB_GMDS_RLBLOCKING_API MCTSState {
/*------------------------------------------------------------------------*/
/** @brief Gives the set of actions that can be tried from the current state
*/
virtual std::queue<MCTSMove *> *actions_to_try() const = 0;
virtual std::deque<MCTSMove *> *actions_to_try() const = 0;
/*------------------------------------------------------------------------*/
/** @brief Performs the @p AMove to change of states
* @param[in] AMove the movement to apply to get to a new state
Expand Down
5 changes: 4 additions & 1 deletion rlBlocking/inc/gmds/rlBlocking/MCTSStatePolycube.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LIB_GMDS_RLBLOCKING_API MCTSStatePolycube: public MCTSState{
/*------------------------------------------------------------------------*/
/** @brief Gives the set of actions that can be tried from the current state
*/
std::queue<MCTSMove *> *actions_to_try() const ;
std::deque<MCTSMove *> *actions_to_try() const ;
/*------------------------------------------------------------------------*/
/** @brief Performs the @p AMove to change of states
* @param[in] AMove the movement to apply to get to a new state
Expand Down Expand Up @@ -69,6 +69,9 @@ class LIB_GMDS_RLBLOCKING_API MCTSStatePolycube: public MCTSState{
/** @brief return the history of the parents quality */
std::vector<double> get_history() const;

/** @brief update the classification of a state */
void update_class();

private :
/** @brief the curved blocking of the current state */
gmds::blocking::CurvedBlocking* m_blocking;
Expand Down
4 changes: 3 additions & 1 deletion rlBlocking/inc/gmds/rlBlocking/MCTSTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LIB_GMDS_RLBLOCKING_API MCTSNode {
/** @brief the parent for the current node*/
MCTSNode *parent;
/** @brief queue of untried actions*/
std::queue<MCTSMove *> *untried_actions;
std::deque<MCTSMove *> *untried_actions;
/** @brief update the nb simulations and the score after a rollout*/
void backpropagate(double w, int n);
public:
Expand Down Expand Up @@ -72,6 +72,8 @@ class LIB_GMDS_RLBLOCKING_API MCTSNode {
MCTSNode *advance_tree(const MCTSMove *m);
/** @brief Return the state of the node. */
const MCTSState *get_current_state() const;
/** @brief Return the children of the node. */
std::vector<MCTSNode *> *get_children();
/** @brief Print the tree and the stats. */
void print_stats() const;
/** @brief Calculate the q rate of a node. It's: wins-looses */
Expand Down
3 changes: 2 additions & 1 deletion rlBlocking/src/MCTSAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ MCTSAgent::~MCTSAgent(){
delete tree;
}
/*----------------------------------------------------------------------------*/
const MCTSMove *MCTSAgent::genmove() {
const MCTSMove *MCTSAgent::genmove()
{
// If game ended from opponent move, we can't do anything
if (tree->get_current_state()->is_terminal()) {
return NULL;
Expand Down
4 changes: 3 additions & 1 deletion rlBlocking/src/MCTSAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void MCTSAlgorithm::execute()

MCTSState *state = new MCTSStatePolycube(this->m_geom, this->m_blocking, std::vector<double> ());
//state->print(); // IMPORTANT: state will be garbage after advance_tree()
MCTSAgent agent(state, 1000);
MCTSAgent agent(state, 100);
do {
agent.feedback();
agent.genmove();
Expand All @@ -38,6 +38,8 @@ void MCTSAlgorithm::execute()
// }
done = new_state->is_terminal();
} while (!done);


std::cout<<"==========================================================="<<std::endl;
std::cout<<"===================== END EXECUTE ALGO====================="<<std::endl;
std::cout<<"==========================================================="<<std::endl;
Expand Down
8 changes: 7 additions & 1 deletion rlBlocking/src/MCTSMovePolycube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace gmds;
MCTSMovePolycube::~MCTSMovePolycube()
{}
/*----------------------------------------------------------------------------*/
MCTSMovePolycube::MCTSMovePolycube(TCellID AIdEdge, TCellID AIdBlock, double AParamCut, bool ATypeMove)
MCTSMovePolycube::MCTSMovePolycube(TCellID AIdEdge, TCellID AIdBlock, double AParamCut, unsigned int ATypeMove)
:m_AIdEdge(AIdEdge),m_AIdBlock(AIdBlock), m_AParamCut(AParamCut),m_typeMove(ATypeMove)
{}
/*----------------------------------------------------------------------------*/
Expand All @@ -18,3 +18,9 @@ MCTSMovePolycube::operator==(const gmds::MCTSMove &AOther) const
&& m_AParamCut == o.m_AParamCut && m_typeMove== o.m_typeMove;
}
/*----------------------------------------------------------------------------*/
void MCTSMovePolycube::print() const
{
std::cout<<"m_AIdEdge : "<< m_AIdEdge<<" ; m_AIdBlock : "<<m_AIdBlock<<" ; m_AParamCut : "<<
m_AParamCut<<" ; m_typeMove : "<<m_typeMove<<std::endl;
}
/*----------------------------------------------------------------------------*/
Loading

0 comments on commit 5ffaab5

Please sign in to comment.