c++ - Combine two base class instances into a derived one -


i have following classes used define tree structure number of specific nodes

class treenode {   std::vector<treenode*> children; } class btnode: public virtual treenode {   virtual bool loadattributes(xml) = 0;   virtual btstate tick() = 0;    void otherfunction1() { used different nodes}   void otherfunction2() { used node types } } 

there couple of specific implementations of btnode class can saved , loaded xml files:

class btspecificnodeone: public btnode {   bool loadattributes(xml) { load node specific data xml }   btstate tick() { specific implementation goes here } } class btspecificnodetwo: public btnode {   bool loadattributes(xml) { load node specific data xml }   btstate tick() { specific implementation goes here } } etc. 

i have genetic algorithm optimises tree structure based on common tree node genome type:

class treenodegenome: public virtual treenode {   bool load(xml);   treenodegenome* crossover(treenodegenome* other);   virtual void mutate() = 0; } 

furthermore, have node specific implementation used within genome

class btspecificnodegenomeone: public btspecificnode, public treenodegenome {   void mutate() { node specific implementation } } class btspecificnodegenometwo: public btspecificnode, public treenodegenome {   void mutate() { node specific implementation } } etc. 

i'd able save , load results of optimisation to/from xml file.

the implementations of btspecificnodeone, btspecificnodetwo, etc. have save/load function use saving results, loading them bit more tricky.

the load function of btnode class rebuilds tree (from xml) based on btnode class (nodes may create children loaded recursively). in order use again in genetic algorithm, need nodes derive treenodegenome class well.

i can rebuild treenodegenome structure based on information contained in treenode, i'm not sure how "merge" these 2 trees together.

i know pretty copy load functions btspecificnodegenomeone, btspecificnodegenometwo, etc. classes wondering if there simpler/cleaner way it?

edit: apparently i'd bit unclear previous post.

i have implemented behaviour tree(bt) class, uses number of different nodes deriving btnode: selector, sequence, different condition , action nodes. bt saved in xml format , can loaded via btnode::loadattributes().

in addition this, have genetic algorithm can optimise tree structures. treenodegenome implements genetic operators of different nodes used during evolution.

during evolution use btspecificnodegenomeone, btspecificnodegenometwo nodes implement both different bt nodes , genetic operators treenodegenome. treenodegenome requires structure of tree encoded in treenode base class , node specific implementations of mutation operator. bt , evolvable tree structure 2 conceptually different things, i'd keep them separate.

my question is: have btnode::loadattributes() function implemented btnodes already, load bt xml file. function creates children btnodes, not evolvable. if want use loaded tree in evolution, need somehow "merge" treenodegenome object.

i can reimplementing loadattributes function in each derived btspecificnodegenome, wondering if there cleaner/simpler way this?


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -