Quantcast

Mashalling/Unmarshalling of GP results in locked/uneditable Variable

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Mashalling/Unmarshalling of GP results in locked/uneditable Variable

disgruntled_young_man

I'm going to have to post this because it's just driving me crazy.  I've
successfully marshalled and unmarshalled a GP population following this
method:

MARSHAL:

            XStream xstream = new XStream();
            PrintWriter outFile = null;
            try {
                outFile = new PrintWriter(new
FileOutputStream("C:\\postgres_backups\\best_runs\\population" + runNumber +
".xml", false));
            } catch (FileNotFoundException ex) {
               
Logger.getLogger(GPProblem.class.getName()).log(Level.SEVERE, null, ex);
            }

            String xml = xstream.toXML(gpGenotypeVar.getGPPopulation());
            outFile.print(xml);
            outFile.close();

UNMARSHAL:

        XStream xstream = new XStream();
        File f = new File(path_to_file + "\\population" + x + ".xml");
        InputStream oi = new FileInputStream(f);
        GPPopulation loadedPop = (GPPopulation) xstream.fromXML(oi);
        gpGenotypevar.getGPPopulation().setGPPrograms(loadedPop);


I've verified the loaded population reflects that exactly which I wanted to
save


I am *not* marshalling/unmarshalling the GPConfiguration as suggested in one
of the other threads similar to this topic, as my settings were locked.

I have a node in my nodeSets called:

CommandGene[][] nodeSets = {
            {
                //the time variable
                _timeVariable = Variable.create(config, "unixTime",
TimeClass.class),
.
.
.

which I set during the evaluate() method

_timeVariable.set(engine.getTimeForIndex(i));  //it is a unix timestamp

======================================================

when running the GP *without* a loaded population my timeVariable is set as
expected and changes as "i" increments.  When I'm running against the loaded
population "i" increments but _timeVariable does not change.  It is locked
to the last "i" value when the population was saved ... I cannot modify it,
nor do I know how to directly access the value to modify it!  I've verified
this even in the saved population's xml file itself:

<org.jgap.gp.terminal.Variable>
                    <m__configuration reference="../../../../../../.."/>
                    <m__noValidation>false</m__noValidation>
                    <m__returnType>GPDummyClasses.TimeClass</m__returnType>
                    <m__arity>0</m__arity>
                    <m__arityMin>0</m__arityMin>
                    <m__arityMax>0</m__arityMax>
                    <m__integerType>false</m__integerType>
                    <m__floatType>false</m__floatType>
                    <m__energy>0.0</m__energy>
                    <m__compareAppData>false</m__compareAppData>
                    <m__subReturnType>0</m__subReturnType>
                    <nodeIndex>0</nodeIndex>
                    <m__name>unixTime</m__name>
                    <m__value class="long">1302788340005</m__value>
</org.jgap.gp.terminal.Variable>

m__value is locked to 1302788340005, and I see that as well in my debugging
attempts for every "i" increment in my evaluate() method's for-loop.  That
m__value is exactly when I stopped running the GP and saved the population.


I'm seriously.. argh!  I need help!  Thanks in advance!
--
View this message in context: http://old.nabble.com/Mashalling-Unmarshalling-of-GP-results-in-locked-uneditable-Variable-tp32452678p32452678.html
Sent from the jgap-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Mashalling/Unmarshalling of GP results in locked/uneditable Variable

disgruntled_young_man
I have solved my issue and believe I've found a bug with how execute_long handles Variables.  If this is actually a "feature" it should probably be called out in the source somewhere, as it took me the dismantling of several classes, re-writting of marshalling (right down to the gene, which doesn't seem to work right either) and several depressive bouts.

Anyway, when I run my GP without a loaded population, set my variable, and in my custom function call:
c.execute_long(n, 0, args)
I successfully get a changing time as expected which was set in my Fitness function in a for-loop.

On the flip side however, if I'm loading a marshalled population and attempt to call:
c.execute_long(n, 0, args)
What is returned is the value that was last marshalled (if you see in my quoted message below):
<m__value class="long">1302788340005</m__value> 

That value is always returned.  I've figured out that if instead (and this works for both loaded and not-loaded populations) in your function you do this:
        Variable unixTime = Variable.getVariable("unixTime");
        long unixTimeVal = ((Long)unixTime.getValue()).longValue();

I receive my changing variable as expected.  I can then replace all execute_long on my first child with this long value.

I hope this saves some poor soul the unbearable torment that I've gone through trying to figure this out.  My trials and tribulations are almost over.  </Firstworldproblem>





disgruntled_young_man wrote
I'm going to have to post this because it's just driving me crazy.  I've
successfully marshalled and unmarshalled a GP population following this
method:

MARSHAL:

            XStream xstream = new XStream();
            PrintWriter outFile = null;
            try {
                outFile = new PrintWriter(new
FileOutputStream("C:\\postgres_backups\\best_runs\\population" + runNumber +
".xml", false));
            } catch (FileNotFoundException ex) {
               
Logger.getLogger(GPProblem.class.getName()).log(Level.SEVERE, null, ex);
            }

            String xml = xstream.toXML(gpGenotypeVar.getGPPopulation());
            outFile.print(xml);
            outFile.close();

UNMARSHAL:

        XStream xstream = new XStream();
        File f = new File(path_to_file + "\\population" + x + ".xml");
        InputStream oi = new FileInputStream(f);
        GPPopulation loadedPop = (GPPopulation) xstream.fromXML(oi);
        gpGenotypevar.getGPPopulation().setGPPrograms(loadedPop);


I've verified the loaded population reflects that exactly which I wanted to
save


I am *not* marshalling/unmarshalling the GPConfiguration as suggested in one
of the other threads similar to this topic, as my settings were locked.

I have a node in my nodeSets called:

CommandGene[][] nodeSets = {
            {
                //the time variable
                _timeVariable = Variable.create(config, "unixTime",
TimeClass.class),
.
.
.

which I set during the evaluate() method

_timeVariable.set(engine.getTimeForIndex(i));  //it is a unix timestamp

======================================================

when running the GP *without* a loaded population my timeVariable is set as
expected and changes as "i" increments.  When I'm running against the loaded
population "i" increments but _timeVariable does not change.  It is locked
to the last "i" value when the population was saved ... I cannot modify it,
nor do I know how to directly access the value to modify it!  I've verified
this even in the saved population's xml file itself:

<org.jgap.gp.terminal.Variable> 
                    <m__configuration reference="../../../../../../.."/> 
                    <m__noValidation>false</m__noValidation> 
                    <m__returnType>GPDummyClasses.TimeClass</m__returnType> 
                    <m__arity>0</m__arity> 
                    <m__arityMin>0</m__arityMin> 
                    <m__arityMax>0</m__arityMax> 
                    <m__integerType>false</m__integerType> 
                    <m__floatType>false</m__floatType> 
                    <m__energy>0.0</m__energy> 
                    <m__compareAppData>false</m__compareAppData> 
                    <m__subReturnType>0</m__subReturnType> 
                    <nodeIndex>0</nodeIndex> 
                    <m__name>unixTime</m__name> 
                    <m__value class="long">1302788340005</m__value> 
</org.jgap.gp.terminal.Variable> 

m__value is locked to 1302788340005, and I see that as well in my debugging
attempts for every "i" increment in my evaluate() method's for-loop.  That
m__value is exactly when I stopped running the GP and saved the population.


I'm seriously.. argh!  I need help!  Thanks in advance!
--
View this message in context: http://old.nabble.com/Mashalling-Unmarshalling-of-GP-results-in-locked-uneditable-Variable-tp32452678p32452678.html
Sent from the jgap-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the
BlackBerry® mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry® DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
jgap-users mailing list
jgap-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jgap-users
Loading...