Original Post
Hello, I have a fairly full featured GP system created and was creating the docs for the lua function set which will be provided. A little about this system.
THe goal is to have cretaed one of the most easily extensible GP system. It is setup where, it executes a lua script that you give to it. all of the functionallity of the system is shown to the lua script and you can choose how to use it. My goal is for this system to be VERY flexible. These are the functions that I have come up with in order to expose the system to the lua scripts. Does anyone have any ideas for changes on these?
I will show you what I have and then explain some high level stuff after:
My home page!!!
Find out about my diy LCD projector and programming projects!
Group* NewGroup() RPG* NewRPG() Mutator* NewMutator() SampleGen* NewSampleGen() Environment* NewEnvironment() dispsettings* NewDispSettings() progsettings* NewProgSettings() env* NewEnvironemnt() /////////////////////////////////////// // RPG functions /////////////////////////////////////// void RPG_LoadFunctionSet( string filename ) This function reads in a list of function names to load into the function set from the plaintext file found at filename. void RPG_SetHeightLimits( int min, int max ) This sets the limits on how large or small a random tree can be. The tree will have no more than max depth and will be a complete tree up until the min depth. These settings are always in effect, even with other methods of RPG. void RPG_CreatePrograms( RPG* rpg, Group* groupmain, int numof ) Creates numof programs using settings in rpg, and adds them to groupmain. /////////////////////////////////////// // Mutator functions /////////////////////////////////////// void Mutator_SetType( Mutator* mutator, string type ) Sets the type of the mutator. The standard options here are "Mutate", "Crossover", "Relocator" and "Collection". many functions are only applicable when the mutator is of a certain type. The types will specified under those functions. void Mutator_OnlyReplaceLikeNodes( Mutator* mutator, bool newval ) ONLY APPLICABLE WHEN TYPE "MUTATE" OR "CROSSOVER" When true, the mutator will replace nodes with other nodes of the same type: functions with other functions, terminals with the same type of terminal. void Mutator_PreserveAirity( Mutator* mutator, bool newval ) ONLY APPLICABLE WHEN TYPE "MUTATE" OR "CROSSOVER" This function will make sure that when a function is replaced, it is replaced by one with the same airity. This may limit the effectiveness of the GP... be cautious when using it. void Mutator_AddMutator( Mutator* mutator, Mutator* newmut ) ONLY APPLICABLE WHEN TYPE "COLLECTION" This will add a mutator to the collection. This type is used so that multipule mutators can be put into one and called all at the same time. void Mutator_MutateSample( Mutator* mutator, Sample* smpl ) Mutates EVERY program in the sample. If a program is included twice, it is mutated twice. /////////////////////////////////////// // SampleGen functions /////////////////////////////////////// void SampleGen_SetType( SampleGen* smplgen, "Basic_Percent" ) Sets the SampleType. Keep in mind that although custom sample methods can be employed, this will be slower due to the extra interface between lua and C... Not sure what the difference will be, just make sure you are aware of it. Some built in Tpyes include: "Basic_Percent": might sort in some order if you tell it to, then only select the top or bottom % of programs. "Basic_Constant": might sort in some order if you tell it to, then only select the top or bottom x # of programs. the # of programs chosen is independent of the # of programs in the group. void SampleGen_AddGroup( SampleGen* smplgen, Group* groupmain ) Adds a group to the sample''s population. Not sure what to do yet when you add a group and it contains programs that are already included... Will be an option when I get around to it. void SampleGen_SortMethodAscending( SampleGen* smplgen, string var ) This will sort the programs in ascending order using a variable defined for all of the programs. Programs that don''t have that variable will be put at the... end or begenning... should probobly make that an option... dang. The only default is score, which all programs have by default. void SampleGen_SortMethodDescending( SampleGen* smplgen, string var ) See SampleGen_SortMethodAscending. void SampleGen_SetPercentChosen( SampleGen* smplgen, float per ) Sets the percentage of programs selected out of the population. a positive percent selects the top percent, and negitive the bottom. void SampleGen_IncludeGroups( SampleGen* smplgen, bool newval ) Iff true, allows groups to be in the population. void SampleGen_IncludeGroupsRec( SampleGen* smplgen, bool newval ) Iff ture, sub-groups are also added to the population. void SampleGen_IncludePorgrams( SampleGen* smplgen, bool newval ) Iff true, allows programs to be in the population. void SampleGen_IncludeProgramsRec( SampleGen* smplgen, bool newval ) Iff ture, programs in sub-groups are also added to the population. Sample* SampleGen( SampleGen* smplgen ) Creates a sample from the settings loaded into smplgen. /////////////////////////////////////// // DispProg Functions /////////////////////////////////////// void DispProg_Rec( DispSettings* dispsettings, bool newval ) When true, every sub-group is alse displayed. void DispProg_Group( DispSettings* dispsettings, Group* groupmain ) Displays every program in the group. If the recursive setting is selected, every sub-group is also displayed /////////////////////////////////////// // Group Functions /////////////////////////////////////// void Group_AddADF( Group* group, Group* adf ) This adds the group adf to the list of ADF groups in group. void Group_AddConstraint( Group* group, string type, int data ) This will add a constraint of type type with the argument of data to Group . This so far has no application other than to help the user avoid mistakes. Similar to using a strongly typed system. If the user knows that the group should never have children groups, then they may specify at creation time and be warned later if someone tried to break this constraint. Created with ADFs in mind. void Group_SetDefaultProgramSettings( Group* group, ProgSettings* progsettings, [bool applytoadfs = true], [bool applytonormal = true], [bool applytochildren] ) All programs which are added to this group get these settings by default. if applyto adfs is true, the settings apply to adfs, (defaults to true). Same goes form applytonormal. Applying to children will only work if the children dont have default settings of their own. void Group_RemoveDefaultSettings( Group* group ) Removes the default settings of the group. /////////////////////////////////////// // Environment Functions /////////////////////////////////////// void Environment_SetDefault( Environment* env ) subsoqiently created programs will have this environment by default void Environment_LoadTxtData( Environment* env, string filename ) loads the file filename in txt format. I need to specify somewhere the standards for the text file. void Environment_NextData( Environment* env ) Increments the data previously loaded from file or inserted through function calls. void Environment_PrevData( Environment* env ) See Environment_NextData. void Environment_AddVariable( Environment* env, string varname ) Adds a variable to the environment. void Environment_AddVariablesFromFile( Environment* env, string filename ) Opens the file in filename and adds the list of variables seperated by a comma or newline to the environment. void Environment_RemoveVariable( Environment* env, string var ) Removes the variable var from the list of varaibles. /////////////////////////////////////// // Program Settings Functions /////////////////////////////////////// void ProgSettings_AddVariable( ProgSettings* progsettings, string varname, string fnname ) Adds a variable to the program settings. void ProgSettings_RemoveVariable( ProgSettings* progsettings, string varname, string fnname ) Removes a variable to the program settings. void ProgSettings_SetDefault( ProgSettings* progsettings ) All new programs will default to these settings. Keep in mind that the default settings for groups take priority over this defualt. void ProgSettings_ApplyToSample( ProgSettings* progsettings, Sample* smpl ) Applies the settings to all of the programs in the sample... should this have priority over the default settings of the group?I also have an RTF vertion but my server doesn''t seem to want to accept it... A simpel lua script is as follows:
-- create all of the objects we will need groupmain = NewGroup() rpgmain = NewRPG() mutator = NewMutator() smplgen = NewSampleGen() envirn = NewEnvironment() -- progdisp = NewProgramDisplay() -- there is only 1 static program displayer... -- just use the functions RPG_LoadFunctionSet( "Default.fns" ) -- min, max RPG_SetHeightLimits( 3, 5 ) -- rpg, group, numofprogs RPG_CreatePrograms( rpgmain, groupmain, 100 ) -- Mutator_SetType( mutator, "Crossover" ) -- Mutator_SetType( mutator, "Relocator" ) Mutator_SetType( mutator, "Mutate" ) -- this is specific to this type of mutator. -- if this were attempted on a mutator which -- doesn''t support it, a pretty error in the -- C++ code should tell us about the mistake. Mutator_OnlyReplaceLikeNodes( true ) -- similar to the mutator''s Set Type SampleGen_SetType( smplgen, "Basic" ) -- this function tells smplgen to generate its -- samples from this group. SampleGen_AddGroup( smplgen, groupmain ) -- this also is specific to this type. (see above) SampleGen_SetPercentChosen( smplgen, 0.05 ) for i = 0, 100 do smpl = SampleGen( smplgen ) Mutator_MutateSample( mutator, smpl ) end -- this function is not recursive by default -- this group has no children groups so this -- isn''t an issue. Use DispProg_GroupRec() -- when it is. DispProg_Group( groupmain )That script would run 100 generations on a simgle population of 100 programs... not to useful, but you get the idea. I would like to know if anyone has any suggestions as to what functionality would be nice. Or if there is any part which isn''t straight forawrd, I''d be happy to explain some more so it is. My hope is that is pretty straight-forward to anyone familiar with GP. lets here the comments! Thanks in advance! Dwiel
Find out about my diy LCD projector and programming projects!