36 #include "GeometryTools.hpp" 37 #include "LatticeBasedMigrationRule.hpp" 38 #include "RandomNumberGenerator.hpp" 40 template<
unsigned DIM>
43 mMovementProbability(0.01)
48 template <
unsigned DIM>
55 template<
unsigned DIM>
61 template<
unsigned DIM>
63 std::vector<unsigned> neighbourIndices,
unsigned gridIndex)
65 std::vector<double> probability_of_moving(neighbourIndices.size(), 0.0);
66 for(
unsigned idx=0; idx<neighbourIndices.size(); idx++)
71 bool already_attached =
false;
72 for (
unsigned seg_index = 0; seg_index < pNode->GetNumberOfSegments(); seg_index++)
74 if(pNode->GetSegment(seg_index)->GetOppositeNode(pNode)->IsCoincident(neighbour_location))
76 already_attached =
true;
89 return probability_of_moving;
92 template<
unsigned DIM>
94 std::vector<unsigned> neighbourIndices)
96 int location_index = -1;
99 std::vector<double> cumulativeProbabilityVector(movementProbabilities.size());
100 std::partial_sum(movementProbabilities.begin(), movementProbabilities.end(), cumulativeProbabilityVector.begin());
102 if (cumulativeProbabilityVector.back() > 1.0)
104 EXCEPTION(
"Cumulative probability of tip cell moving is greater than one");
108 double cumulativeProbability = cumulativeProbabilityVector.back();
109 double random_number = RandomNumberGenerator::Instance()->ranf();
112 if(random_number < cumulativeProbability)
114 for (
unsigned ind = 0; ind < cumulativeProbabilityVector.size(); ind++)
116 if (random_number <= cumulativeProbabilityVector[ind])
118 location_index = neighbourIndices[ind];
123 return location_index;
126 template<
unsigned DIM>
132 template<
unsigned DIM>
137 EXCEPTION(
"A regular grid is required for this type of migration rule.");
142 EXCEPTION(
"A vessel network is required for this type of migration rule.");
146 std::vector<int> indices(rNodes.size(), -1);
149 std::vector<std::vector<boost::shared_ptr<VesselNode<DIM> > > > point_node_map = this->
mpGrid->GetPointNodeMap();
152 std::vector<std::vector<unsigned> > neighbour_indices = this->
mpGrid->GetNeighbourData();
155 for(
unsigned idx = 0; idx < rNodes.size(); idx++)
158 unsigned grid_index = this->
mpGrid->GetNearestGridIndex(rNodes[idx]->rGetLocation());
164 double sum = std::fabs(std::accumulate(probability_of_moving.begin(), probability_of_moving.end(), 0.0));
virtual ~LatticeBasedMigrationRule()
LatticeBasedMigrationRule()
virtual std::vector< int > GetIndices(const std::vector< boost::shared_ptr< VesselNode< DIM > > > &rNodes)
virtual int GetNeighbourMovementIndex(std::vector< double > movementProbabilities, std::vector< unsigned > neighbourIndices)
boost::shared_ptr< RegularGrid< DIM > > mpGrid
static boost::shared_ptr< LatticeBasedMigrationRule< DIM > > Create()
virtual std::vector< double > GetNeighbourMovementProbabilities(boost::shared_ptr< VesselNode< DIM > > pNode, std::vector< unsigned > neighbourIndices, unsigned gridIndex)
void SetMovementProbability(double movementProbability)
boost::shared_ptr< VesselNetwork< DIM > > mpVesselNetwork
double mMovementProbability