From a45ea752862a45a0868940280aeb837af270cf22 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Wed, 29 Aug 2007 06:18:35 +0000 Subject: [PATCH] Added a Whirl model, which favors reversals, instead of using the standard --- src/model.cpp | 4 +++- src/modelidentifier.cpp | 2 +- src/models.cpp | 11 +++++++++++ src/models.h | 18 ++++++++++++++++++ src/test/modelidentifiertest.cpp | 2 +- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/model.cpp b/src/model.cpp index efd5c5f..f801f12 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -41,7 +41,9 @@ bool operator<(const Model& lh,const Model& rh){ Model Model::modelFactory(const std::string& name){ if (name == "X"){ return Model(new Models::X()); - }else if(name == "Whirl" || name == "Standard"){ + }else if(name == "Whirl"){ + return Model(new Models::Whirl()); + }else if(name == "Standard"){ return Model(new Models::ModelImpl()); }else if(name == "Zipper"){ return Model(new Models::Zipper()); diff --git a/src/modelidentifier.cpp b/src/modelidentifier.cpp index 820d75a..a7c67b8 100644 --- a/src/modelidentifier.cpp +++ b/src/modelidentifier.cpp @@ -83,7 +83,7 @@ priority_queue > ModelIdentifier::identify(const GeneOrder& g priority_queue > scores; scores.push(pair(output[0],Model(new Models::X))); scores.push(pair(output[1],Model(new Models::Zipper))); - scores.push(pair(output[2],Model(new Models::ModelImpl))); + scores.push(pair(output[2],Model(new Models::Whirl))); scores.push(pair(output[3],Model(new Models::FatX))); scores.push(pair(output[4],Model(new Models::Cloud))); return scores; diff --git a/src/models.cpp b/src/models.cpp index a8289c7..0511dd4 100644 --- a/src/models.cpp +++ b/src/models.cpp @@ -36,6 +36,17 @@ const char* ModelImpl::name(){ } +double Whirl::score(const SortAction& sa, const GeneOrder& go){ + const ReverseAction* ra = dynamic_cast(&sa.impl()); + + if (ra){ + return 1; + } + return -1; +} +const char* Whirl::name(){ + return "Whirl"; +} double X::score(const SortAction& sa, const GeneOrder& go){ const ReverseAction* ra = dynamic_cast(&sa.impl()); diff --git a/src/models.h b/src/models.h index f037071..c1c96d1 100644 --- a/src/models.h +++ b/src/models.h @@ -46,6 +46,24 @@ class ModelImpl { virtual const char* name(); }; +/** + * A model that favors reversals. + */ +class Whirl : public ModelImpl { + public: + /** + * Returns a higher score for reversals and a lower score + * for all other actions. + * + * \see Model::score + */ + double score(const SortAction& sa, const GeneOrder& go); + + /** + * \see Model::name + */ + const char* name(); +}; /** * A model that favors symmetric reversal, resulting in an X-like diff --git a/src/test/modelidentifiertest.cpp b/src/test/modelidentifiertest.cpp index 7a0cedd..b4848cc 100644 --- a/src/test/modelidentifiertest.cpp +++ b/src/test/modelidentifiertest.cpp @@ -67,7 +67,7 @@ protected: GeneOrder uniform(_uniform.begin(),_uniform.end()); pq = mi.identify(uniform); - CPPUNIT_ASSERT_EQUAL(string("Standard"),string(pq.top().second.name())); + CPPUNIT_ASSERT_EQUAL(string("Whirl"),string(pq.top().second.name())); GeneOrder zipper(_zipper.begin(),_zipper.end()); pq = mi.identify(zipper); -- 2.39.2