1 // $Id: force.h,v 1.9 2002/07/30 01:44:41 mkkuhner Exp
2 
3 /*
4   Copyright 2002  Peter Beerli, Mary Kuhner, Jon Yamato and Joseph Felsenstein
5 
6   This software is distributed free of charge for non-commercial use
7   and is copyrighted.  Of course, we do not guarantee that the software
8   works, and are not responsible for any damage you may cause or have.
9 */
10 
11 #ifndef FORCE_H
12 #define FORCE_H
13 
14 #include "constants.h"
15 #include "parameter.h"     // for Parameter member object
16 #include "plforces.h"      // for PLForces classes
17 #include "stringx.h"
18 #include "types.h"
19 #include "vectorx.h"
20 #include "xml_strings.h"   // for string constants in GetXMLName()
21 #include "epoch.h"
22 #include <deque>
23 #include <string>
24 #include <utility>         // std::pair
25 #include <vector>
26 #include "paramstat.h"
27 
28 class Event;
29 class Registry;
30 class ChainPack;
31 class ChainOut;
32 class DataPack;
33 class ForceSummary;
34 class ForceParameters;
35 class Summary;
36 class IntervalData;
37 class Locus;
38 class Region;
39 class UIVarsPrior;
40 
41 // in .cpp
42 // #include "forcesummary.h"   for forcesummary getter functions
43 // #include "event.h"          to set up Event vectors in arrangers
44 
45 /******************************************************************
46  The Force class defines a polymorphic object which embodies
47  information about one of the evolutionary forces active in the
48  program.  It has four main functions:
49 
50  (1)  To indicate, by its presence in the ForceSummary, that the
51  force is active.
52 
53  (2)  To manage the parameters associated with its force (for
54  example, the theta values associated with Coalescence).  It maintains
55  a vector of Parameter objects for this purpose.
56 
57  (3)  To provide information to the rest of the program about
58  its force (quickestimate, name, dimensionality, table headers, etc.)
59 
60  (4)  To act as a factory for the Event objects (representing concepts
61  such as "a coalescence of two active lineages") used by the Arrangers,
62  and for the Summary objects (representing presence of a force) used
63  by the TreeSummary.
64 
65  A fifth main function, handling force-specific math, may be
66  added when we integrate the posterior-likelihood module.
67 
68  The only place Force objects normally exist is inside of the
69  (singular) ForceSummary object, which owns them.
70 
71  Forces are only created after both data reading and user input
72  (menu) are completed.
73 
74  Forces are by design, neither copyable nor assignable.
75 
76  Written by Mary Kuhner and Jon Yamato
77  * 04/04/02 Peter Beerli added PLforces objects
78  * 11/14/02 Peter Beerli made Profile-modifier force specific
79  * 6/9/10 Mary Kuhner and Jon Yamato added DivForce and DivMigForce
80  ******************************************************************/
81 
82 class Force
83 {
84   private:
85     // these are undefined because we should not be copying or
86     // assigning Forces. The registry creates one force of each
87     // used type, and puts them in the ForceSummary object.
88     Force();                       // undefined
89     Force(const Force& src);       // undefined
90     Force&     operator=(const Force& src);   // undefined
91 
92   protected:
93 
94     force_type  m_tag;            // identifying tag of force
95     string      m_name;           // concise name of the force
96     string      m_fullname;       // full name of the force
97     string      m_paramname;      // concise name of the parameter type
98     string      m_fullparamname;  // full name of the parameter type
99 
100     std::vector<Parameter> m_parameters;  // all parameters related to this force
101 
102     long m_maxevents;  // maximum "events" of this force allowed per tree
103     double m_defvalue; // default value of parameters for this force
104     double m_maxvalue; // maximum allowed value for each initial param estimate
105     double m_minvalue; // minimum allowed value for each initial param estimate
106     double m_maximizer_maxvalue;// maximum value allowed during maximization
107     double m_maximizer_minvalue;// minimum value allowed during maximiztion
108 
109     double m_highval;           // a reasonable upper guess for the force.
110     double m_lowval;            // a reasonable lower guess for the force.
111     double m_highmult;          // The stepsize up for high guesses.
112     double m_lowmult;           // The stepsize down for low guesses.
113 
114     StringVec1d m_axisname;      // name of each table axis
115 
116     DoubleVec1d m_paramgroupmultipliers; // dim: by param group, multiplier
117     // is ratio first/head param over other param
118     // NB Assumes never more than 2 parameters in a multiplicative group!
119     // if we ever need more than 2, need to redimension
120 
121     // postlike forces related objects that contain functions that are called by
122     // point() and wait() in the post-likelihood calculation
123     PLForces * m_plforceptr;    // holds force object; OWNING POINTER
124 
125     // When parameters are constrained to be equal to one another
126     // that information lives here:
127     std::vector<ParamGroup> m_identgroups;
128 
129     // When parameters are constrained to be multiples of one another
130     // that information lives here:
131     std::vector<ParamGroup> m_multgroups;
132 
133     //This variable is solely for the XML writer.  Hmmm.
134     Prior m_defaultPrior;
135 
136     // Utility function used by InsertParameters
137     DoubleVec1d PopParameters(DoubleVec1d& parameters);
138 
139     // used by Force::ToXML()
140     virtual std::string MakeOpeningTag(unsigned long nspaces) const;
141     std::vector<proftype> GetProfileTypes() const;
142     std::vector<ParamStatus> GetParamstatuses() const;
143 
144   public:
145 
146     Force(   force_type          tag,
147              string              name,
148              string              fullname,
149              string              paramname,
150              string              fullparamname,
151              std::vector<Parameter>   parameters,
152              long int            maxevents,
153              double              defvalue,
154              double              maxvalue,
155              double              minvalue,
156              double              maximizer_maxvalue,
157              double              maximizer_minvalue,
158              double              highval,
159              double              lowval,
160              double              highmult,
161              double              lowmult,
162              std::vector<ParamGroup> identgroups,
163              std::vector<ParamGroup> multgroups,
164              const DoubleVec1d &       paramgroupmults,
165              const UIVarsPrior &       prior);
166 
~Force()167     virtual ~Force() { delete m_plforceptr; };
168 
169     // Report writing functions -- these could be implemented at base level
170     // except for MigrationParameter
171     virtual StringVec1d    MakeStartParamReport() const;
172     virtual StringVec1d    MakeChainParamReport(const ChainOut& chout) const;
173     virtual bool           HasNoVaryingParameters() const;
174 
175     // RTTI for use by ForceSummary::GetPartitionForces()
IsPartitionForce()176     virtual bool           IsPartitionForce() const { return false; };
177     // RTTI for use by ForceSummary::GetSelectedSites()
IsLocalPartitionForce()178     virtual bool           IsLocalPartitionForce() const { return false; };
IsSexualForce()179     virtual bool           IsSexualForce() const    { return false; };
180     // RTTI for use by ForceSummary::UsingStick()
IsStickForce()181     virtual bool           IsStickForce() const     { return false; };
182 
183     // Getters
GetTag()184     force_type     GetTag()           const { return m_tag; };
GetFullName()185     string         GetFullName()      const { return m_fullname; };
GetFullparamname()186     string         GetFullparamname() const { return m_fullparamname; };
GetShortparamname()187     string         GetShortparamname()const { return m_paramname; };
GetClassName()188     virtual string         GetClassName()     const { return "Class"; };
189     virtual string         GetXMLName()       const = 0;
190     virtual long int       ReportDimensionality() const = 0;
GetAxisname()191     StringVec1d    GetAxisname()      const { return m_axisname; };
192     DoubleVec2d    GetMles()          const;
193     DoubleVec1d    GetPopmles()       const;
194 
GetMaxEvents()195     long int       GetMaxEvents()     const { return m_maxevents; };
GetDefaultValue()196     double         GetDefaultValue()  const { return m_defvalue; };
197     MethodTypeVec1d GetMethods()      const;
GetNParams()198     long int       GetNParams()       const { return m_parameters.size(); };
199 
200     StringVec1d    GetAllParamNames() const;
GetHighVal()201     double GetHighVal() const  { return m_highval; };
GetLowVal()202     double GetLowVal() const   { return m_lowval; };
GetHighMult()203     double GetHighMult() const { return m_highmult; };
GetLowMult()204     double GetLowMult() const  { return m_lowmult; };
GetMaximizerMaxVal()205     double GetMaximizerMaxVal() const { return m_maximizer_maxvalue; };
GetMaximizerMinVal()206     double GetMaximizerMinVal() const { return m_maximizer_minvalue; };
207 
GetParameters()208     std::vector<Parameter>& GetParameters()  { return m_parameters; };
GetParameters()209     const std::vector<Parameter>& GetParameters() const { return m_parameters; };
210 
211     // used by ForceParameters::SetAllTo(), polymorphic in PartitionForce
212     virtual DoubleVec1d CreateVectorOfParametersWithValue(double val) const;
213 
214     // returns pointer to PLForces object [that holds the force specific
215     // wait() and point() functions
GetPLForceFunction()216     PLForces * GetPLForceFunction() { return m_plforceptr; };
217 
218     // SummarizeProfTypes--used by ReportPage::SetupColhdr()
219     proftype       SummarizeProfTypes() const;
220 
221     // Handle grouping of parameters constrained to be related to one another
222     ULongVec2d     GetIdenticalGroupedParams() const;
223     ULongVec2d     GetMultiplicativeGroupedParams() const;
224     DoubleVec1d    GetParamGroupMultipliers() const;
225 
226     virtual StringVec1d    ToXML(unsigned long int nspaces) const;
227 
228     // Setters
229     // No setters for intrinsic class qualities like name, as these
230     // are built into the subclasses.
231     // SetParameters is a helper function for
232     // ForceSummary::SetAllParameters() used in ParamVector dtor.
SetParameters(const std::vector<Parameter> & src)233     void        SetParameters(const std::vector<Parameter>& src)
234     { m_parameters = src; };
235     // true if value is set, false otherwise
SetPartIndex(long int)236     virtual bool        SetPartIndex(long int) { return false; };
237 
238     // used by Branch::IsAMember()
239     virtual bool        IsAMember(const LongVec1d& m1, const LongVec1d& m2) const;
240 
241     // used by ForceSummary::SummarizeData()
242     std::deque<bool> UseCalculatedValues() const;
243     virtual double      Truncate(double target) const;
244 
245     // generally interface into a ForceParameters object
246     virtual DoubleVec1d RetrieveGlobalParameters(const ForceParameters& fp) const;
247     virtual DoubleVec1d RetrieveRegionalParameters(const ForceParameters& fp) const;
248     virtual DoubleVec1d RetrieveGlobalLogParameters(const ForceParameters& fp) const;
249     virtual DoubleVec1d RetrieveRegionalLogParameters(const ForceParameters& fp) const;
250     // FindOrdinalPosition used by BayesArranger::Rearrange
251     unsigned long int FindOrdinalPosition(long int cannonicalorder) const;
252 
253     // The following functions manage the Events associated with a particular
254     // force.  Events are owned by the recipient (an Arranger).
255     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs) const = 0;
ModifyEvents(const ForceSummary & fs,std::vector<Event * > &)256     virtual void           ModifyEvents(const ForceSummary& fs,
257                                         std::vector<Event*>&) const {};
258 
259     // The following function is used in creating the partition holder
260     // in each branch.
GetNPartitions()261     virtual long int      GetNPartitions() const { return 0; };
262 
263     // The following is a factory function to make Summary objects for the
264     // TreeSummary
265     virtual Summary* CreateSummary(IntervalData& interval, bool
266                                    shortness) const = 0;
267 }; // Force
268 
269 //------------------------------------------------------------------------------------
270 
271 class RecForce : public Force
272 {
273   private:
274     RecForce();                       // unimplemented to block call
275     RecForce(const RecForce& src);    // unimplemented to block call
276     RecForce& operator=(const RecForce& src);   // unimplemented to block call
277 
278   public:
279     RecForce ( std::vector<Parameter>   parameters,
280                long                maxEvents,
281                std::vector<ParamGroup> identgroups,
282                std::vector<ParamGroup> multgroups,
283                const DoubleVec1d&        paramgroupmults,
284                const UIVarsPrior &       prior);
~RecForce()285     virtual                ~RecForce() {};
286 
IsSexualForce()287     virtual bool           IsSexualForce() const { return true; };
GetXMLName()288     virtual string         GetXMLName() const { return xmlstr::XML_TAG_RECOMBINATION; };
289     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs) const;
290     virtual Summary*       CreateSummary(IntervalData& interval, bool shortness) const;
ReportDimensionality()291     virtual long int       ReportDimensionality() const { return 1L; };
292 
293 }; // RecForce
294 
295 //------------------------------------------------------------------------------------
296 
297 class CoalForce : public Force
298 {
299   private:
300     CoalForce();                     // unimplemented to block call
301     CoalForce(const CoalForce& src); // unimplemented to block call
302     CoalForce& operator=(const CoalForce& src); // unimplemented to block call
303 
304   public:
305     CoalForce( std::vector<Parameter>   parameters,
306                long int            maxEvents,
307                bool                withGrowth,
308                bool                withLogisticSelection,
309                std::vector<ParamGroup> identgroups,
310                std::vector<ParamGroup> multgroups,
311                const DoubleVec1d&        paramgroupmults,
312                const UIVarsPrior &       prior);
313 
~CoalForce()314     virtual                ~CoalForce() {};
315 
GetXMLName()316     virtual string         GetXMLName() const { return xmlstr::XML_TAG_COALESCENCE; };
317     virtual std::vector<Event*> MakeEvents(const ForceSummary & fs) const;
318     virtual Summary*       CreateSummary(IntervalData& interval, bool shortness) const;
319     virtual long int       ReportDimensionality() const;
320 
321 }; // CoalForce
322 
323 //------------------------------------------------------------------------------------
324 
325 class GrowthForce : public Force
326 {
327   private:
328     GrowthForce();                        // unimplemented to block call
329     GrowthForce(const GrowthForce& src);  // unimplemented to block call
330     GrowthForce& operator=(const GrowthForce& src); // unimplemented to block call
331 
332   protected:
333     virtual std::string MakeOpeningTag(unsigned long int nspaces) const;
334   public:
335     GrowthForce ( std::vector<Parameter>   parameters,
336                   long                maxEvents,
337                   std::vector<ParamGroup> identgroups,
338                   std::vector<ParamGroup> multgroups,
339                   const DoubleVec1d&        paramgroupmults,
340                   const UIVarsPrior &       prior);
~GrowthForce()341     virtual              ~GrowthForce() {};
342 
GetXMLName()343     virtual string         GetXMLName() const { return xmlstr::XML_TAG_GROWTH; };
344     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs)   const;
345     virtual void           ModifyEvents(const ForceSummary& fs, std::vector<Event*>& events) const;
346 
347     virtual Summary*       CreateSummary(IntervalData& interval, bool shortness) const;
348 
349     virtual DoubleVec1d    RetrieveGlobalLogParameters(const ForceParameters& fp) const;
350     virtual DoubleVec1d    RetrieveRegionalLogParameters(const ForceParameters& fp) const;
351 
352     virtual long int       ReportDimensionality() const;
353 
354 }; // GrowthForce
355 
356 //------------------------------------------------------------------------------------
357 
358 class LogisticSelectionForce : public Force
359 {
360   private:
361     LogisticSelectionForce();                        // unimplemented to block call
362     LogisticSelectionForce(const LogisticSelectionForce& src);  // unimplemented to block call
363     LogisticSelectionForce& operator=(const LogisticSelectionForce& src); // unimplemented to block call
364 
365   protected:
366     virtual std::string MakeOpeningTag(unsigned long int nspaces) const;
367   public:
368     LogisticSelectionForce(std::vector<Parameter> parameters,
369                            long                maxEvents,
370                            long                paramvecindex,
371                            std::vector<ParamGroup> identgroups,
372                            std::vector<ParamGroup> multgroups,
373                            const DoubleVec1d&        paramgroupmults,
374                            const UIVarsPrior &       prior);
~LogisticSelectionForce()375     virtual              ~LogisticSelectionForce() {};
376 
GetXMLName()377     virtual string         GetXMLName() const { return xmlstr::XML_TAG_LOGISTICSELECTION; };
378     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs)   const;
379     virtual void           ModifyEvents(const ForceSummary& fs, std::vector<Event *> & events) const;
380 
381     virtual Summary *      CreateSummary(IntervalData& interval, bool shortness) const;
382 
383     virtual DoubleVec1d    RetrieveGlobalLogParameters(const ForceParameters & fp) const;
384     virtual DoubleVec1d    RetrieveRegionalLogParameters(const ForceParameters & fp) const;
385 
386     virtual long int       ReportDimensionality() const;
387 
388 }; // LogisticSelectionForce
389 
390 //------------------------------------------------------------------------------------
391 
392 class RegionGammaForce : public Force
393 {
394   private:
395     RegionGammaForce();                           // unimplemented to block call
396     RegionGammaForce(const RegionGammaForce& src);// unimplemented to block call
397 
398   public:
399     RegionGammaForce(std::vector<Parameter> parameters,
400                      std::vector<ParamGroup> identgroups,
401                      std::vector<ParamGroup> multgroups,
402                      const DoubleVec1d&        paramgroupmults,
403                      const UIVarsPrior& prior);
~RegionGammaForce()404     virtual ~RegionGammaForce() {};
405 
GetXMLName()406     virtual string          GetXMLName() const { return xmlstr::XML_TAG_REGION_GAMMA; };
407     virtual std::vector<Event *> MakeEvents(const ForceSummary & fs) const;
408     virtual Summary *       CreateSummary(IntervalData& interval, bool shortness) const;
409     virtual long int        ReportDimensionality() const;
410 
411 }; // RegionGammaForce
412 
413 //------------------------------------------------------------------------------------
414 
415 class PartitionForce : public Force
416 {
417     PartitionForce();                             // unimplemented to block call
418     PartitionForce(const PartitionForce& src);    // unimplemented to block call
419     PartitionForce& operator=(const PartitionForce& src); // unimplemented to block call
420   protected:
421     long int     m_npartitions;
422     long int     m_partindex;   // what is my index in a branch's partitionvector?
423 
424     virtual std::string  GetXMLStatusTag() const = 0;
425 
426   public:
427     PartitionForce( force_type          tag,
428                     string              name,
429                     string              fullname,
430                     string              paramname,
431                     string              fullparamname,
432                     std::vector<Parameter>   parameters,
433                     long int            maxevents,
434                     double              defvalue,
435                     double              maxvalue,
436                     double              minvalue,
437                     double              maximizer_maxvalue,
438                     double              maximizer_minvalue,
439                     double              highval,
440                     double              lowval,
441                     double              highmult,
442                     double              lowmult,
443                     long                npartitions,
444                     std::vector<ParamGroup> identgroups,
445                     std::vector<ParamGroup> multgroups,
446                     const DoubleVec1d&        paramgroupmults,
447                     const UIVarsPrior &       prior);
~PartitionForce()448     virtual              ~PartitionForce() {};
449 
450     // RTTI for use by ForceSummary::GetPartitionForces()
IsPartitionForce()451     virtual bool         IsPartitionForce() const { return true; };
452     virtual long int     ChoosePartition(long int origpart, long int chosenpart,
453                                          bool islow, long int midpoint) const;
454 
455     virtual void         ModifyEvents(const ForceSummary& fs, std::vector<Event*>& events) const;
456 
457     virtual StringVec1d  MakeStartParamReport() const;
458     virtual StringVec1d  MakeChainParamReport(const ChainOut& chout) const;
459 
460     // used by ForceSummary::SummarizeData()
461     virtual bool         SetPartIndex(long int val);
462 
GetNPartitions()463     virtual long int     GetNPartitions() const { return m_npartitions; };
GetPartIndex()464     virtual long int     GetPartIndex() const { return m_partindex; };
465 
466     virtual bool         IsAMember(const LongVec1d& m1, const LongVec1d& m2) const;
467 
468     virtual DoubleVec1d  CreateVectorOfParametersWithValue(double val) const;
469 
470     virtual DoubleVec1d  SumXPartsToParts(const DoubleVec1d& xparts) const;
471     virtual DoubleVec1d  SumXPartsToParts(const DoubleVec1d& xparts, const DoubleVec1d& growths, double etime) const;
472 
473     // used by SampleXML::ToXML()
474     virtual std::string  MakeStatusXML(const std::string& mystatus) const;
475 
476 }; // PartitionForce
477 
478 //------------------------------------------------------------------------------------
479 
480 class LocalPartitionForce : public PartitionForce
481 {
482   private:
483     LocalPartitionForce(); // undefined
484     LocalPartitionForce(const LocalPartitionForce& src);   // undefined
485     LocalPartitionForce& operator=(const LocalPartitionForce& src); // undefined
486 
487   protected:
488     long int m_localsite;  // the site that the force is dependant on
489 
490   public:
491     LocalPartitionForce(    force_type          tag,
492                             string              name,
493                             string              fullname,
494                             string              paramname,
495                             string              fullparamname,
496                             std::vector<Parameter>   parameters,
497                             long int            maxevents,
498                             double              defvalue,
499                             double              maxvalue,
500                             double              minvalue,
501                             double              maximizer_maxvalue,
502                             double              maximizer_minvalue,
503                             double              highval,
504                             double              lowval,
505                             double              highmult,
506                             double              lowmult,
507                             long                npartitions,
508                             long                localsite,
509                             std::vector<ParamGroup> identgroups,
510                             std::vector<ParamGroup> multgroups,
511                             const DoubleVec1d&        paramgroupmults,
512                             const UIVarsPrior &       prior);
~LocalPartitionForce()513     virtual              ~LocalPartitionForce() {};
IsLocalPartitionForce()514     virtual bool         IsLocalPartitionForce() const { return true; };
515     virtual long int     ChoosePartition(long int origpart, long int chosenpart, bool islow, long int midpoint) const;
516 
517     // getter used by ToXML
GetLocalSite()518     long int     GetLocalSite() const { return m_localsite; };
519     virtual StringVec1d  ToXML(unsigned long int nspaces) const;
520 
521 }; // LocalPartitionForce
522 
523 //------------------------------------------------------------------------------------
524 
525 class MigForce : public PartitionForce
526 {
527   private:
528     MigForce();                                // undefined
529     MigForce(const MigForce& src);             // undefined
530     MigForce& operator=(const MigForce& src);  // undefined
531 
532   protected:
533     virtual std::string    GetXMLStatusTag() const;
534 
535   public:
536     MigForce ( std::vector<Parameter>   parameters,
537                long                maxEvents,
538                long                numPops,
539                std::vector<ParamGroup> identgroups,
540                std::vector<ParamGroup> multgroups,
541                const DoubleVec1d&        paramgroupmults,
542                const UIVarsPrior &       prior);
~MigForce()543     virtual                ~MigForce() {};
GetClassName()544     virtual string         GetClassName() const { return "Population"; };
545 
GetXMLName()546     virtual string         GetXMLName() const { return xmlstr::XML_TAG_MIGRATION; };
547     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs)   const;
548     virtual Summary*       CreateSummary(IntervalData& interval, bool shortness) const;
MakeStatusXML(const std::string & mystatus)549     virtual std::string    MakeStatusXML(const std::string& mystatus) const { return string(""); };
ReportDimensionality()550     virtual long int       ReportDimensionality() const { return 3L; };
551 
552 }; // MigForce
553 
554 //------------------------------------------------------------------------------------
555 
556 class DivMigForce : public PartitionForce
557 // Migration in the presence of divergence; should never exist unless
558 // DivForce also exists
559 // MDEBUG should this inherit from MigForce instead of PartitionForce?
560 {
561   private:
562     DivMigForce();                                  // undefined
563     DivMigForce(const DivMigForce& src);            // undefined
564     DivMigForce& operator=(const DivMigForce& src); // undefined
565 
566   protected:
567     virtual std::string    GetXMLStatusTag() const;
568 
569   public:
570     DivMigForce ( std::vector<Parameter>   parameters,
571                   long                maxEvents,
572                   long                numPops,
573                   std::vector<ParamGroup> identgroups,
574                   std::vector<ParamGroup> multgroups,
575                   const DoubleVec1d&        paramgroupmults,
576                   const UIVarsPrior &       prior);
~DivMigForce()577     virtual                ~DivMigForce() {};
GetClassName()578     virtual string         GetClassName() const { return "Population"; };
579 
GetXMLName()580     virtual string         GetXMLName() const { return xmlstr::XML_TAG_DIVMIG; };
581     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs)   const;
582     virtual Summary*       CreateSummary(IntervalData& interval, bool shortness) const;
MakeStatusXML(const std::string & mystatus)583     virtual std::string    MakeStatusXML(const std::string& mystatus) const { return string(""); };
ReportDimensionality()584     virtual long int       ReportDimensionality() const { return 3L; };
585 
586 }; // DivMigForce
587 
588 //------------------------------------------------------------------------------------
589 
590 class DiseaseForce : public LocalPartitionForce
591 {
592   private:
593     // there exists no quickcalculator equivalent for disease
594     DiseaseForce();                                   // undefined
595     DiseaseForce(const DiseaseForce& src);            // undefined
596     DiseaseForce& operator=(const DiseaseForce& src); // undefined
597 
598   protected:
599     virtual std::string  GetXMLStatusTag() const;
600 
601   public:
602     DiseaseForce(const DataPack& dpack, const UIVars& uivars);
603     DiseaseForce ( std::vector<Parameter>   parameters,
604                    long int            maxEvents,
605                    bool                hasLogisticSelection,
606                    long                numDiseaseStates,
607                    long                localsite,
608                    std::vector<ParamGroup> identgroups,
609                    std::vector<ParamGroup> multgroups,
610                    const DoubleVec1d&        paramgroupmults,
611                    const UIVarsPrior &       prior);
~DiseaseForce()612     virtual ~DiseaseForce() {};
613 
GetXMLName()614     virtual string          GetXMLName() const { return xmlstr::XML_TAG_DISEASE; };
615     virtual std::vector<Event *> MakeEvents(const ForceSummary & fs) const;
616 
617     virtual Summary *       CreateSummary(IntervalData& interval, bool shortness) const;
ReportDimensionality()618     virtual long int        ReportDimensionality() const { return 3L; };
619 
620 }; // DiseaseForce
621 
622 //------------------------------------------------------------------------------------
623 
624 class StickForce : public Force
625 {
626   private:
627     // the default ctor, copy ctor, and operator= are all
628     // deliberately undefined to block call
629     StickForce();
630     StickForce(const StickForce& src);
631     StickForce& operator=(const StickForce& src);
632 
633   protected:
634     double m_percentchange;
635     StickForce (force_type         tag,
636                 string             name,
637                 string             fullname,
638                 string             paramname,
639                 string             fullparamname,
640                 std::vector<Parameter>  parameters,
641                 long int           maxevents,
642                 double             defvalue,
643                 double             maxvalue,
644                 double             minvalue,
645                 double             maximizer_maxvalue,
646                 double             maximizer_minvalue,
647                 double             highval,
648                 double             lowval,
649                 double             highmult,
650                 double             lowmult,
651                 std::vector<ParamGroup> identgroups,
652                 std::vector<ParamGroup> multgroups,
653                 const DoubleVec1d&       paramgroupmults,
654                 const UIVarsPrior& prior);
655 
656   public:
~StickForce()657     virtual        ~StickForce() {};
IsStickForce()658     virtual bool   IsStickForce() const     { return true; };
659 };
660 
661 //------------------------------------------------------------------------------------
662 
663 class StickExpGrowForce : public StickForce
664 {
665   private:
666     // the default ctor, copy ctor, and operator= are all
667     // deliberately undefined to block call
668     StickExpGrowForce();
669     StickExpGrowForce(const StickExpGrowForce& src);
670     StickExpGrowForce& operator=(const StickExpGrowForce& src);
671 
672     const double m_negln, m_posln;
673 
674   protected:
675 
676     virtual std::string MakeOpeningTag(unsigned long int nspaces) const;
677 
678   public:
679     StickExpGrowForce  ( std::vector<Parameter> parameters,
680                          long int          maxEvents,
681                          std::vector<ParamGroup> identgroups,
682                          std::vector<ParamGroup> multgroups,
683                          const DoubleVec1d&     paramgroupmults,
684                          const UIVarsPrior & prior);
~StickExpGrowForce()685     virtual             ~StickExpGrowForce() {};
686 
687     virtual string         GetXMLName() const;
688     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs) const;
689     virtual void           ModifyEvents(const ForceSummary& fs, std::vector<Event*>& events) const;
690     virtual Summary*       CreateSummary(IntervalData& interval, bool shortness) const;
691 
692     virtual DoubleVec1d    RetrieveGlobalLogParameters
693     (const ForceParameters& fp) const;
694     virtual DoubleVec1d    RetrieveRegionalLogParameters
695     (const ForceParameters& fp) const;
696 
697     virtual long int       ReportDimensionality() const;
698 };
699 
700 //------------------------------------------------------------------------------------
701 
702 class StickSelectForce : public StickForce
703 {
704   private:
705     // The default ctor, copy ctor, and operator= are all deliberately undefined to block call.
706     StickSelectForce();
707     StickSelectForce(const StickSelectForce& src);
708     StickSelectForce& operator=(const StickSelectForce& src);
709 
710   protected:
711 
712     virtual std::string MakeOpeningTag(unsigned long int nspaces) const;
713 
714   public:
715     StickSelectForce  ( std::vector<Parameter> parameters,
716                         long int          maxEvents,
717                         std::vector<ParamGroup> identgroups,
718                         std::vector<ParamGroup> multgroups,
719                         const DoubleVec1d&     paramgroupmults,
720                         const UIVarsPrior & prior);
~StickSelectForce()721     virtual             ~StickSelectForce() {};
722 
723     virtual string         GetXMLName() const;
724     virtual long int       ReportDimensionality() const;
725     virtual Summary *       CreateSummary(IntervalData& interval, bool shortness) const;
726 
727     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs) const ;
728 
729     virtual DoubleVec1d    RetrieveGlobalLogParameters
730     (const ForceParameters& fp) const;
731     virtual DoubleVec1d    RetrieveRegionalLogParameters
732     (const ForceParameters& fp) const;
733 };
734 
735 //------------------------------------------------------------------------------------
736 
737 class DivForce : public Force
738 {
739   private:
740     // the default ctor, copy ctor, and operator= are all
741     // deliberately undefined to block call
742     DivForce();
743     DivForce(const DivForce& src);
744     DivForce& operator=(const DivForce& src);
745 
746     std::vector<Epoch> m_epochs;
747 
748   public:
749     DivForce           ( std::vector<Parameter> parameters,
750                          long int          maxEvents,
751                          std::vector<ParamGroup> identgroups,
752                          std::vector<ParamGroup> multgroups,
753                          const DoubleVec1d&     paramgroupmults,
754                          const UIVarsPrior & prior,
755                          const std::vector<std::vector<std::string> >& newpops,
756                          const std::vector<std::string>& ancestors,
757                          const DataPack& dpack);
~DivForce()758     virtual             ~DivForce() {};
759 
GetXMLName()760     virtual string         GetXMLName() const { return xmlstr::XML_TAG_DIVERGENCE; };
761     virtual long int       ReportDimensionality() const;
762     virtual Summary *       CreateSummary(IntervalData& interval, bool shortness) const;
763 
764     virtual std::vector<Event*> MakeEvents(const ForceSummary& fs) const ;
GetEpochs()765     const std::vector<Epoch>* GetEpochs() const { return &m_epochs; };
766     virtual StringVec1d    ToXML(unsigned long int nspaces) const;
767 };
768 
769 //------------------------------------------------------------------------------------
770 //------------------------------------------------------------------------------------
771 
772 // These free functions pretty-print a matrix of various dimensions
773 
774 StringVec1d Tabulate(double params, long int width);
775 StringVec1d Tabulate(const DoubleVec1d & params, long int width);
776 StringVec1d Tabulate(const DoubleVec2d & params, long int width);
777 
778 #endif // FORCE_H
779 
780 //____________________________________________________________________________________
781