[Avida-SVN] r2170 - branches/uml/source/main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Thu Nov 1 12:34:23 PDT 2007


Author: hjg
Date: 2007-11-01 15:34:23 -0400 (Thu, 01 Nov 2007)
New Revision: 2170

Modified:
   branches/uml/source/main/cBirthChamber.cc
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cOrganism.h
   branches/uml/source/main/cPopulation.cc
   branches/uml/source/main/cPopulation.h
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cTaskLib.h
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
Log:
first part of new model caching

Modified: branches/uml/source/main/cBirthChamber.cc
===================================================================
--- branches/uml/source/main/cBirthChamber.cc	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cBirthChamber.cc	2007-11-01 19:34:23 UTC (rev 2170)
@@ -210,11 +210,6 @@
     
   child_genotype->IncDeferAdjust();
 
-  // FOR UML branch - hjg
-  child_array[0]->setParentXMI(parent.getUMLModel()->getXMI());
-  child_array[0]->setParentBonus(parent.getParentBonus());  
-  child_array[0]->setParentScenarioCompletion(parent.getUMLModel()->getScenarioCompletion());
-
   return true;
 }
 

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cOrganism.cc	2007-11-01 19:34:23 UTC (rev 2170)
@@ -598,6 +598,13 @@
 		m_model.setMaxTrans(m_model.numTrans());
 	} 
 
+	// Check if the model has been previously cached
+	if (m_world->GetPopulation().findModel(m_model.getXMI())) {
+		m_model.setIsCached(true);
+	} else {
+	// If not, enter it into the cache.
+		m_world->GetPopulation().addModel(m_model.getXMI());
+	}
 
   const tArray<double> & resource_count = m_interface->GetResources();
   
@@ -671,19 +678,7 @@
 	m_world->GetStats().addGuards(m_model.numGuards());
 	m_world->GetStats().addActions(m_model.numActions());
 	m_world->GetStats().addStateDiagrams(m_model.numSDs());
-	
-	
-	if ((m_model.getBonusInfo("spinn1") > 0) && 
-		(m_model.getBonusInfo("spinn2") > 0)) { 
-		m_world->GetStats().N1andN2Passed();
-	}
-	
 
-	
-//	m_world->GetStats().addTransLabel(transition_labels.size());
-
-  
-  
 }
 
 cUMLModel* cOrganism::getUMLModel()

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cOrganism.h	2007-11-01 19:34:23 UTC (rev 2170)
@@ -147,9 +147,9 @@
   int m_guard_index;
   int m_action_index;*/	
   cUMLModel m_model;		
-  std::string m_parent_xmi; 
-  std::map<std::string, float> m_parent_bonus;  
-  std::vector<double> m_parent_scenario_completion;
+//  std::string m_parent_xmi; 
+//  std::map<std::string, float> m_parent_bonus;  
+//  std::vector<double> m_parent_scenario_completion;
 
   cOrganism(); // @not_implemented
   cOrganism(const cOrganism&); // @not_implemented
@@ -312,7 +312,7 @@
   void modelCheck(cAvidaContext& ctx);
   cUMLModel* getUMLModel();
 //  cUMLModel* getParentUMLModel() { return m_parent_model; } 
-  std::string getParentXMI() { return m_parent_xmi; }
+//  std::string getParentXMI() { return m_parent_xmi; }
   int getStateDiagramIndex() { return m_state_diag; } 
 //  bool lastStateDiagram () { m_state_diag = getUMLModel()->getStateDiagramSize(); }
 //  bool firstStateDiagram() { m_state_diag = 0; }  
@@ -320,12 +320,12 @@
   cUMLStateDiagram* getStateDiagram();
 //  void printStats();
 //  void setParentModel(cUMLModel* m) { m_parent_model = m; } 
-  void setParentXMI(std::string s) { m_parent_xmi = s; } 
-  void setParentBonus (std::map<std::string, float> v) { m_parent_bonus = v; }
-  float getParentBonus (std::string s) { return m_parent_bonus[s]; }
-  std::map<std::string, float> getParentBonus() { return m_parent_bonus; }
-  std::vector<double> getParentScenarioCompletion() { return m_parent_scenario_completion; } 
-  void setParentScenarioCompletion (std::vector<double> s) { m_parent_scenario_completion = s; }
+//  void setParentXMI(std::string s) { m_parent_xmi = s; } 
+//  void setParentBonus (std::map<std::string, float> v) { m_parent_bonus = v; }
+//  float getParentBonus (std::string s) { return m_parent_bonus[s]; }
+//  std::map<std::string, float> getParentBonus() { return m_parent_bonus; }
+//  std::vector<double> getParentScenarioCompletion() { return m_parent_scenario_completion; } 
+//  void setParentScenarioCompletion (std::vector<double> s) { m_parent_scenario_completion = s; }
 
  
 // The jump functions jump the index of the various vectors either forward (+ int) or backwards (- int)

Modified: branches/uml/source/main/cPopulation.cc
===================================================================
--- branches/uml/source/main/cPopulation.cc	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cPopulation.cc	2007-11-01 19:34:23 UTC (rev 2170)
@@ -2801,9 +2801,12 @@
 }
 
 // Add a model to the cache
-void cPopulation::addAModel(string mod, map<string, float> rewards){
+void cPopulation::addModel(string mod){
+	map<string, float> rewards;
 	model_cache[mod] = rewards;
 }
 
   
+  
+
   
\ No newline at end of file

Modified: branches/uml/source/main/cPopulation.h
===================================================================
--- branches/uml/source/main/cPopulation.h	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cPopulation.h	2007-11-01 19:34:23 UTC (rev 2170)
@@ -212,7 +212,7 @@
   // UML Branch: 
   bool findModel(string);						// Check to see if a model is present in a model cache. 
   float getReward(string, string);				// Get the reward for a specific task for a specific model.
-  void addAModel(string, map<string, float>);	// Add a model to the cache.
+  void addModel(string);	// Add a model to the cache.
 
   // Saving and loading...
   bool SaveClone(std::ofstream& fp);

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cTaskLib.cc	2007-11-01 19:34:23 UTC (rev 2170)
@@ -413,8 +413,8 @@
 	  NewTask(name, "Successfully created 5 states", &cTaskLib::Task_NumStates);  	  
   else if (name == "numTrans") // 
 	  NewTask(name, "Successfully created 5 transitions", &cTaskLib::Task_NumTrans);
-  else if (name == "prop-tr") // 
-	  NewTask(name, "Diagram included trigger", &cTaskLib::Task_PropTrigger);	
+/*  else if (name == "prop-tr") // 
+	  NewTask(name, "Diagram included trigger", &cTaskLib::Task_PropTrigger);	*/
   else if (name == "hydra") // 
 	  NewTask(name, "Successfully ran hydra", &cTaskLib::Task_Hydra);	  	
   else if (name == "spin1") // 
@@ -2943,23 +2943,13 @@
 double cTaskLib::Task_Scenarios(cTaskContext& ctx) const
 {
 	double bonus = 0.0; 
-//	double temp_bonus = 0;
 	std::string sc_name;
 	cOrganism* org = ctx.getOrganism();
 	
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		bonus = org->getUMLModel()->checkForScenarios();
-	} else { 
-		bonus = org->getParentBonus("scenarios"); 
-		org->getUMLModel()->setScenarioCompletion(org->getParentScenarioCompletion());
-	}
+	bonus = org->getUMLModel()->checkForScenarios();
 	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenarios", bonus);		
+//	m_world->GetStats().addScenarioCompletion(org->getUMLModel()->getScenarioCompletion());
 	
-	m_world->GetStats().addScenarioCompletion(org->getUMLModel()->getScenarioCompletion());
-	
 	return bonus;
 }
 
@@ -2996,25 +2986,16 @@
 
 	temp = organism->getUMLModel()->getXMI();
 	
-	// call hydra when a // all scenario hits its max?
-	// all are non-zero?
-	if (!organism->getUMLModel()->readyForHydra()) {
+	// trigger when?
+/*	if (!organism->getUMLModel()->readyForHydra()) {
 		
 		organism->getUMLModel()->setBonusInfo("hydra", bonus);
 		
 		return 0;
-	}
+	}*/
 		
 	m_world->GetStats().HydraAttempt();
-
-	if (organism->getParentXMI() == temp) {
 	
-		bonus = organism->getParentBonus("hydra"); 
-		organism->getUMLModel()->setBonusInfo("hydra", bonus);	
-		return bonus;
-	}		
-
-
 	unsigned int status_total = 0;
 	int status=0;
 
@@ -3093,7 +3074,6 @@
 		bonus = 1.0;
 	}
 	
-	organism->getUMLModel()->setBonusInfo("hydra", bonus);	
 	return bonus;
 	
 }
@@ -3146,28 +3126,16 @@
 }
 
 double cTaskLib::Task_SpinN1(cTaskContext& ctx) const {
-	cOrganism* organism = ctx.getOrganism();
+//	cOrganism* organism = ctx.getOrganism();
 	double bonus = 0.0;
 		
-	if (organism->getUMLModel()->getBonusInfo("spinw1") <= 1)	
-	{ 
-		organism->getUMLModel()->setBonusInfo("spinn1", bonus);	
-		return bonus;
-	}
+	// Only trigger if W1 passes
 
 	
 	m_world->GetStats().N1Attempt();
 
-
-	if (organism->getParentXMI() == organism->getUMLModel()->getXMI()) {
+	bonus = SpinCoprocess(ctx, "N1");
 	
-		bonus = organism->getParentBonus("spinn1"); 
-	}	else {
-	
-		bonus = SpinCoprocess(ctx, "N1");
-	}
-	
-	organism->getUMLModel()->setBonusInfo("spinn1", bonus);	
 	if (bonus > 0) 	m_world->GetStats().N1Passed();
 
 	return bonus;
@@ -3176,29 +3144,17 @@
 
 
 double cTaskLib::Task_SpinW1(cTaskContext& ctx) const { 
-	cOrganism* organism = ctx.getOrganism();
+//	cOrganism* organism = ctx.getOrganism();
 	double bonus = 0.0;
 	
+	// Only trigger if Hydra passes?
 	
-	if	(organism->getUMLModel()->getBonusInfo("hydra") == 0)
-	{ 
-		return bonus;
-	}
-	
 	m_world->GetStats().W1Attempt();
 
+	bonus = SpinWitnessCoprocess(ctx, "W1");
 	
-	if ((organism->getParentXMI()) == (organism->getUMLModel()->getXMI())) {	
-		bonus = organism->getParentBonus("spinw1"); 
-	}	else {
-	
-		bonus = SpinWitnessCoprocess(ctx, "W1");
-	}
-	
-	organism->getUMLModel()->setBonusInfo("spinw1", bonus);	
 	if (bonus > 0) 	m_world->GetStats().W1Passed();
 	
-
 	return bonus;
 }
 
@@ -3207,24 +3163,11 @@
 	cOrganism* organism = ctx.getOrganism();
 	double bonus = 0.0;
 	
-	if (organism->getUMLModel()->getBonusInfo("spinw2") <= 1)	
-	{ 
-		organism->getUMLModel()->setBonusInfo("spinn2", bonus);	
-		return bonus;
-	}
-	
+	// Only trigger if witness is true?	
 	m_world->GetStats().N2Attempt();
 
+	bonus = SpinCoprocess(ctx, "N2");
 	
-	if (organism->getParentXMI() == organism->getUMLModel()->getXMI()) {
-	
-		bonus = organism->getParentBonus("spinn2"); 
-	}	else {
-	
-		bonus = SpinCoprocess(ctx, "N2");
-	}
-	
-	organism->getUMLModel()->setBonusInfo("spinn2", bonus);	
 	if (bonus > 0) 	m_world->GetStats().N2Passed();
 
 	return bonus;
@@ -3236,22 +3179,11 @@
 	cOrganism* organism = ctx.getOrganism();
 	double bonus = 0.0;
 
-	if	(organism->getUMLModel()->getBonusInfo("hydra") == 0)	
-	{ 
-		return bonus;
-	}
-
-	
+	// Only trigger if Hydra passed.
 	m_world->GetStats().W2Attempt();
 		
-	if (organism->getParentXMI() == organism->getUMLModel()->getXMI()) {	
-		bonus = organism->getParentBonus("spinw2"); 
-	}	else {
+	bonus = SpinWitnessCoprocess(ctx, "W2");
 	
-		bonus = SpinWitnessCoprocess(ctx, "W2");
-	}
-
-	organism->getUMLModel()->setBonusInfo("spinw2", bonus);	
 	if (bonus > 0) 	m_world->GetStats().W2Passed();
 
 	return bonus;
@@ -3259,7 +3191,7 @@
 
 
 
-double cTaskLib::Task_PropTrigger(cTaskContext& ctx) const {
+/*double cTaskLib::Task_PropTrigger(cTaskContext& ctx) const {
 	// This task checks for the trigger of the property.
 	cOrganism* organism = ctx.getOrganism();
 	double bonus = 0.0;
@@ -3269,7 +3201,7 @@
 	}
 	
 	return bonus;
-}
+}*/
 
 double cTaskLib::Task_MinTrans(cTaskContext& ctx) const { 
 	// This task rewards organisms for having fewer edges
@@ -3304,8 +3236,6 @@
 		}
 	}
 	
-	organism->getUMLModel()->setBonusInfo("isDeterministic", max_bonus - nd_penalty);	
-
 	return max_bonus - nd_penalty;
 }
 
@@ -3335,20 +3265,14 @@
 double cTaskLib::Task_ViolateN1(cTaskContext& ctx) const { 
 	
 	std::ostringstream strstrm;
-	cOrganism* organism = ctx.getOrganism();
+//	cOrganism* organism = ctx.getOrganism();
 
 	double bonus = 0; 
-	if (organism->getParentXMI() == organism->getUMLModel()->getXMI()) {
-		
-		bonus = organism->getParentBonus("not-n1"); 
-	}	else {
-		if ((SpinCoprocess(ctx, "N1")) == 0) { 
+
+	if ((SpinCoprocess(ctx, "N1")) == 0) { 
 			bonus = 1;
-		}
 	}
-	
-	organism->getUMLModel()->setBonusInfo("not-n1", bonus);	
-	
+		
 	if (bonus) {
 		
 		strstrm << "cp tmp.xmi "  << "violate-n1" << "." << m_world->GetStats().GetUpdate() << "." << ctx.getOrganism()->GetID();

Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cTaskLib.h	2007-11-01 19:34:23 UTC (rev 2170)
@@ -290,7 +290,7 @@
   double Task_Scenarios(cTaskContext& ctx) const;
   double Task_NumStates(cTaskContext& ctx) const;
   double Task_NumTrans(cTaskContext& ctx) const;
-  double Task_PropTrigger(cTaskContext& ctx) const;
+//  double Task_PropTrigger(cTaskContext& ctx) const;
   double Task_Hydra(cTaskContext& ctx) const;
   double SpinCoprocess(cTaskContext& ctx, const std::string& neverclaimFile) const;
   double SpinWitnessCoprocess(cTaskContext& ctx, const std::string& neverclaimFile) const;

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cUMLModel.cc	2007-11-01 19:34:23 UTC (rev 2170)
@@ -180,13 +180,14 @@
   state_diagrams = _cfg_state_diagrams;
   scenarios = _cfg_scenarios;
   hydraMode = _cfg_hydra_mode;  
+  isCached = false;
 }
 
 
 cUMLModel::~cUMLModel()
 {}
 
-float cUMLModel::getBonusInfo (std::string s)  
+/*float cUMLModel::getBonusInfo (std::string s)  
 { 
 	float val;
 	std::map<std::string, float>::iterator bonus_info_pointer;
@@ -199,7 +200,7 @@
 		val = 0;
 	}
 	return val; 
-}
+}*/
 
 
 cUMLStateDiagram* cUMLModel::getStateDiagram (unsigned int x) 
@@ -302,28 +303,16 @@
 	// Iterate through list of scnearios; Call each scenario on the appropriate state diagram
 	// Accrue results.
 	// Save bonus info.
-	scenario_completion.resize(scenarios.size());
+//	scenario_completion.resize(scenarios.size());
 	for (unsigned int i=0; i< scenarios.size(); i++) { 
 		s = scenarios[i];
 		temp_bonus = getStateDiagram(s.stateDiagramID)->findPath(s.path, s.shouldLoop, s.startState);
-//		std::cout << "TEMP BONUS: " << temp_bonus << std::endl;
-//		total_bonus += temp_bonus;
 				
 		complete_bonus = s.path.size() + s.shouldLoop; 
 		if (s.startState >= 0) complete_bonus++;
 		
-//		if (temp_bonus == complete_bonus) {
-////			bonus_info["scenario"+i] = 1;
-//			scenario_completion[i] = temp_bonus / complete_bonus;
-////			std::cout << "scenario complete " << std::endl;
-//		} else {
-////			bonus_info["scenario"+i] = 0;
-//			scenario_completion[i] = 0;
-////			std::cout << "scenario incomplete " << std::endl;
-//
 		total_bonus += (temp_bonus / complete_bonus);
-//		}
-	scenario_completion[i] = temp_bonus / complete_bonus;
+//	scenario_completion[i] = temp_bonus / complete_bonus;
 	}
 		
 	return total_bonus;
@@ -342,16 +331,16 @@
 	switch (hydraMode){
 	case 0:
 		ret_val = 1;
-		for (unsigned int i=0; i< scenario_completion.size(); i++) { 
+		/*for (unsigned int i=0; i< scenario_completion.size(); i++) { 
 				//ret_val &= scenario_completion[i];
 				if (scenario_completion[i] != 1) ret_val &= 0;
-		}
+		}*/
 		break;
 	case 1:
 		ret_val = 0;
-		for (unsigned int i=0; i< scenario_completion.size(); i++) { 
+		/*for (unsigned int i=0; i< scenario_completion.size(); i++) { 
 				if (scenario_completion[i] == 1) ret_val = 1;
-		}
+		}*/
 		break;
 	case 2:
 		ret_val = 0;
@@ -361,11 +350,11 @@
 		break;
 	case 4:
 		ret_val = 1;
-		if (!(getBonusInfo("isDeterministic"))) { ret_val=0; break; }
+		/*if (!(getBonusInfo("isDeterministic"))) { ret_val=0; break; }
 		for (unsigned int i=0; i< scenario_completion.size(); i++) { 
 			//ret_val &= scenario_completion[i];
 			if (scenario_completion[i] != 1) ret_val &= 0;
-		}
+		}*/
 		break;
 	case 5: 
 		ret_val =1;
@@ -396,4 +385,7 @@
 	
 }
 
-
+bool cUMLModel::checkIsCached()
+{
+	return isCached;
+}

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2007-11-01 18:27:22 UTC (rev 2169)
+++ branches/uml/source/main/cUMLModel.h	2007-11-01 19:34:23 UTC (rev 2170)
@@ -48,10 +48,10 @@
 	cUMLStateDiagram* getStateDiagram (unsigned int); 
 	
 	// Set and access the bonus info for a model. Should be used by the tasks
-	void setBonusInfo (std::string s, float f) { bonus_info[s] = f; } 
-	float getBonusInfo (std::string);  
-	std::vector<double> getScenarioCompletion() { return scenario_completion; } 
-	void setScenarioCompletion(std::vector<double> s)  { scenario_completion = s; }
+//	void setBonusInfo (std::string s, float f) { bonus_info[s] = f; } 
+//	float getBonusInfo (std::string);  
+//	std::vector<double> getScenarioCompletion() { return scenario_completion; } 
+//	void setScenarioCompletion(std::vector<double> s)  { scenario_completion = s; }
 		
 	// Get the number of, well, everything
 	int numStates();
@@ -64,7 +64,10 @@
 	
 	// check if the model is ready for hydra
 	bool readyForHydra(); 
+	bool checkIsCached();
+	void setIsCached (bool b) {isCached = b; }
 
+
 protected: 
 	static xmi_info xi;
 	std::string	xmi; 
@@ -72,8 +75,9 @@
 	std::vector<cUMLStateDiagram> state_diagrams;
 	std::map<std::string, float> bonus_info;
 	std::vector<scenario_info> scenarios;
-	std::vector<double> scenario_completion;
+//	std::vector<double> scenario_completion;
 	int hydraMode; 
+	bool isCached; // This value indicates whether the model has previously been cached.
 	
   // The following are set once per Avida experiment, when the first cUMLModel is constructed:
   static bool _cfgLoaded; //!< Whether or not we've already loaded seed-model.cfg.




More information about the Avida-cvs mailing list