]> ruin.nu Git - germs.git/commitdiff
Added a Whirl model, which favors reversals, instead of using the standard
authorMichael Andreen <harv@ruin.nu>
Wed, 29 Aug 2007 06:18:35 +0000 (06:18 +0000)
committerMichael Andreen <harv@ruin.nu>
Wed, 29 Aug 2007 06:18:35 +0000 (06:18 +0000)
src/model.cpp
src/modelidentifier.cpp
src/models.cpp
src/models.h
src/test/modelidentifiertest.cpp

index efd5c5f4d9ae6fc85d2b1e8cb6ac0177a32c0aa3..f801f12d6ec2f8dcc90288df63d5397a820a3a5a 100644 (file)
@@ -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());
index 820d75abd73bbc58a215a704652502e17388893a..a7c67b82c77c5ed3e01335158755221693b2f09d 100644 (file)
@@ -83,7 +83,7 @@ priority_queue<pair<double,Model> > ModelIdentifier::identify(const GeneOrder& g
        priority_queue<pair<double,Model> > scores;
        scores.push(pair<double,Model>(output[0],Model(new Models::X)));
        scores.push(pair<double,Model>(output[1],Model(new Models::Zipper)));
-       scores.push(pair<double,Model>(output[2],Model(new Models::ModelImpl)));
+       scores.push(pair<double,Model>(output[2],Model(new Models::Whirl)));
        scores.push(pair<double,Model>(output[3],Model(new Models::FatX)));
        scores.push(pair<double,Model>(output[4],Model(new Models::Cloud)));
        return scores;
index a8289c7b3f9a5056dc2dc8fb9a3caefbf885c8d3..0511dd4726b231e38b3521981d01ba3ccf793831 100644 (file)
@@ -36,6 +36,17 @@ const char* ModelImpl::name(){
 }
 
 
+double Whirl::score(const SortAction& sa, const GeneOrder& go){
+       const ReverseAction* ra = dynamic_cast<const ReverseAction*>(&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<const ReverseAction*>(&sa.impl());
index f037071b0843684ce16ccb2e29e94aaac38aeb9a..c1c96d1cb52addfdade3d847df8929b1536d8fd7 100644 (file)
@@ -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
index 7a0cedd889e98c8ffe77663e3cecc89d58e6bd2e..b4848cc30326410550b9fea3fe23e4ede54bebf5 100644 (file)
@@ -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);