[Avida-SVN] r1841 - branches/uml/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Tue Jul 24 09:46:43 PDT 2007
Author: hjg
Date: 2007-07-24 12:46:42 -0400 (Tue, 24 Jul 2007)
New Revision: 1841
Modified:
branches/uml/source/main/cOrganism.cc
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:
add min-trans task
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-07-23 19:07:36 UTC (rev 1840)
+++ branches/uml/source/main/cOrganism.cc 2007-07-24 16:46:42 UTC (rev 1841)
@@ -602,6 +602,10 @@
if(GetCellID()==-1) return;
m_model.printXMI();
+ // Update the value of max trans
+ if (m_model.numTrans() > m_model.getMaxTrans()) {
+ m_model.setMaxTrans(m_model.numTrans());
+ }
const tArray<double> & resource_count = m_interface->GetResources();
@@ -683,6 +687,8 @@
m_world->GetStats().N1andN2Passed();
}
+
+
// m_world->GetStats().addTransLabel(transition_labels.size());
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-07-23 19:07:36 UTC (rev 1840)
+++ branches/uml/source/main/cTaskLib.cc 2007-07-24 16:46:42 UTC (rev 1841)
@@ -430,6 +430,9 @@
NewTask(name, "Successfully ran Spin", &cTaskLib::Task_SpinN2);
else if (name == "spin-w2") //
NewTask(name, "Successfully ran Spin witness trace", &cTaskLib::Task_SpinW2);
+ else if (name == "min-trans") //
+ NewTask(name, "Minimizing edges", &cTaskLib::Task_MinTrans);
+
/* else if (name == "mult_trans") //
NewTask(name, "Successfully completed multiple transitions", &cTaskLib::Task_MultTrans);*/
@@ -3162,7 +3165,6 @@
if (organism->getParentXMI() == temp) {
bonus = organism->getParentBonus("hydra");
- //if (bonus) ctx.m_task_success_complete = true;
organism->getUMLModel()->setBonusInfo("hydra", bonus);
return bonus;
}
@@ -3228,14 +3230,10 @@
assert(done==subavida);
// if there are no errors, return 0 from hydraulic. otherwise, return non-zero.
- if(status != 0) {
-// organism->setBonusInfo("hydra", 0.0);
-// ctx.m_task_success_complete = false;
+ if(status != 0) {
bonus = 0.0;
} else {
m_world->GetStats().HydraPassed();
-// organism->setBonusInfo("hydra", 1.0);
-// ctx.m_task_success_complete = true;
bonus = 1.0;
}
@@ -3246,7 +3244,7 @@
double cTaskLib::SpinCoprocess(cTaskContext& ctx, const std::string& neverclaimFile) const {
- cOrganism* organism = ctx.getOrganism();
+// cOrganism* organism = ctx.getOrganism();
std::string cmd = "cat " + neverclaimFile + " >> tmp.pr && ./spin -a tmp.pr &> /dev/null";
if(system(cmd.c_str())!=0) return 0.0;
@@ -3263,7 +3261,7 @@
// strstrm << ".xml";
// if(system(strstrm.str().c_str())!=0) return 0.0;
- return 1.0;
+ return 5.0;
}
double cTaskLib::SpinWitnessCoprocess(cTaskContext& ctx, const std::string& neverclaimFile) const {
@@ -3287,7 +3285,7 @@
double cTaskLib::Task_SpinN1(cTaskContext& ctx) const {
cOrganism* organism = ctx.getOrganism();
double bonus = 0.0;
-
+
if (organism->getUMLModel()->getBonusInfo("spinw1") == 0)
{
organism->getUMLModel()->setBonusInfo("spinn1", bonus);
@@ -3295,6 +3293,9 @@
}
+ m_world->GetStats().N1Attempt();
+
+
if (organism->getParentXMI() == organism->getUMLModel()->getXMI()) {
bonus = organism->getParentBonus("spinn1");
@@ -3304,6 +3305,7 @@
}
organism->getUMLModel()->setBonusInfo("spinn1", bonus);
+ if (bonus > 0) m_world->GetStats().N1Passed();
return bonus;
}
@@ -3314,6 +3316,7 @@
cOrganism* organism = ctx.getOrganism();
double bonus = 0.0;
+
if ((organism->getUMLModel()->getBonusInfo("scenario1") != 2) ||
(organism->getUMLModel()->getBonusInfo("scenario3") != 3) ||
// (organism->getUMLModel()->getBonusInfo("scenario4") != 3) ||
@@ -3322,6 +3325,9 @@
return bonus;
}
+ m_world->GetStats().W1Attempt();
+
+
if ((organism->getParentXMI()) == (organism->getUMLModel()->getXMI())) {
bonus = organism->getParentBonus("spinw1");
} else {
@@ -3330,6 +3336,8 @@
}
organism->getUMLModel()->setBonusInfo("spinw1", bonus);
+ if (bonus > 0) m_world->GetStats().W1Passed();
+
return bonus;
}
@@ -3345,6 +3353,9 @@
return bonus;
}
+ m_world->GetStats().N2Attempt();
+
+
if (organism->getParentXMI() == organism->getUMLModel()->getXMI()) {
bonus = organism->getParentBonus("spinn2");
@@ -3354,6 +3365,7 @@
}
organism->getUMLModel()->setBonusInfo("spinn2", bonus);
+ if (bonus > 0) m_world->GetStats().N2Passed();
return bonus;
}
@@ -3369,7 +3381,8 @@
{
return bonus;
}
-
+
+ m_world->GetStats().W2Attempt();
if (organism->getParentXMI() == organism->getUMLModel()->getXMI()) {
bonus = organism->getParentBonus("spinw2");
@@ -3379,6 +3392,7 @@
}
organism->getUMLModel()->setBonusInfo("spinw2", bonus);
+ if (bonus > 0) m_world->GetStats().W2Passed();
return bonus;
}
@@ -3394,6 +3408,32 @@
bonus = 1.0;
}
-// ctx.m_task_success_complete = ctx.m_task_success_complete && bonus;
return bonus;
}
+
+double cTaskLib::Task_MinTrans(cTaskContext& ctx) const {
+ // This task rewards organisms for having fewer edges
+ cOrganism* organism = ctx.getOrganism();
+ cUMLModel* mod = organism->getUMLModel();
+ double bonus = 0.0;
+ int mt, nt;
+
+
+ if ((organism->getUMLModel()->getBonusInfo("spinw1") == 0) &&
+ (organism->getUMLModel()->getBonusInfo("spinw2") == 0)) {
+ return bonus;
+ }
+
+ // Ok. Subtract the number of edges from the maximum number of edges seen so far.
+ mt = mod->getMaxTrans();
+ nt = mod->numTrans();
+
+ if (mt > 0) {
+ bonus = 1 + mt - nt;
+ bonus /= mt;
+ }
+
+ return bonus;
+
+}
+
Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h 2007-07-23 19:07:36 UTC (rev 1840)
+++ branches/uml/source/main/cTaskLib.h 2007-07-24 16:46:42 UTC (rev 1841)
@@ -300,7 +300,8 @@
double Task_SpinN1(cTaskContext& ctx) const;
double Task_SpinN2(cTaskContext& ctx) const;
double Task_SpinW1(cTaskContext& ctx) const;
- double Task_SpinW2(cTaskContext& ctx) const;
+ double Task_SpinW2(cTaskContext& ctx) const;
+ double Task_MinTrans(cTaskContext& ctx) const;
// double Task_MultTrans(cTaskContext& ctx) const;
};
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2007-07-23 19:07:36 UTC (rev 1840)
+++ branches/uml/source/main/cUMLModel.cc 2007-07-24 16:46:42 UTC (rev 1841)
@@ -30,6 +30,7 @@
std::string cUMLModel::xmi_end = loadFile("xmi_end");
std::string cUMLModel::xmi_class1 = loadFile("class1_xmi");
std::string cUMLModel::xmi_class2 = loadFile("class2_xmi");
+int cUMLModel::max_trans = 0;
cUMLModel::cUMLModel()
Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h 2007-07-23 19:07:36 UTC (rev 1840)
+++ branches/uml/source/main/cUMLModel.h 2007-07-24 16:46:42 UTC (rev 1841)
@@ -24,6 +24,10 @@
std::string getXMI(); // get the XMI version of the model.
void printXMI(); // create the XMI version of the model.
+ // Used to update and get the max number of trans.
+ int getMaxTrans() { return max_trans; }
+ void setMaxTrans( int m ) { max_trans = m; }
+
// Access the size of the state diagrams and also a specific state diagram
unsigned int getStateDiagramSize() { return state_diagrams.size(); }
cUMLStateDiagram* getStateDiagram (unsigned int);
@@ -47,9 +51,12 @@
static std::string xmi_end;
static std::string xmi_class1;
static std::string xmi_class2;
+ static int max_trans;
std::vector<cUMLStateDiagram> state_diagrams;
std::map<std::string, float> bonus_info;
};
+
+
#endif
More information about the Avida-cvs
mailing list