void PlayLayer::randomPlayer() { std::default_random_engine generator1(time(NULL)); std::uniform_int_distribution<int> colsr(0,GAME_COLS-1); auto colsRandom= std::bind(colsr,generator1); std::default_random_engine generator2(time(NULL)*GAME_ROWS*GAME_COLS); std::uniform_int_distribution<int> rowsr(0,GAME_ROWS-1); auto rowsRandom= std::bind(colsr,generator2); int count = 0; bool isTag = true; while(isTag) { if (count == 200) { isTag =false; break; } auto player = players[colsRandom()][rowsRandom()]; player->staus = NOT_DIE; player->setNotDieColor(); count++; } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// studyTwinPeakPerformance //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void AnalysisSrpa::studyTwinPeakPerformance( const std::vector< double >& frequencies, const std::vector< double >& frequencyDifference, double amp2 ) { Synthesizer::SineGenerator generator1( m_samplingInfo ); Synthesizer::SineGenerator generator2( m_samplingInfo ); FeatureAlgorithm::SrSpecPeakAlgorithm peakAlg( 0.25, "PeakAlg", this ); WaveAnalysis::SpectralReassignmentTransform transform( m_samplingInfo, m_fourierSize, m_zeroPadSize, 1 ); generator1.setAmplitude( m_amplitude ); generator2.setAmplitude( amp2 ); Math::RegularAccumArray statusHist( 3, -0.5, NumHistStatusItems - 0.5 ); /// Loop over frequencies. for ( size_t iFreq = 0; iFreq < frequencies.size(); ++iFreq ) { double frequency = frequencies[ iFreq ]; generator1.setFrequency( frequency ); RawPcmData::Ptr data1 = generator1.generate( m_fourierSize ); RealVector freqDiffX; RealVector freqDiffYMin; RealVector freqDiffYMax; /// Loop over frequency differences. for ( size_t iFreqDiff = 0; iFreqDiff < frequencyDifference.size(); ++iFreqDiff ) { double frequency2 = generator1.getFrequency() + frequencyDifference[ iFreqDiff ]; generator2.setFrequency( frequency2 ); RawPcmData::Ptr data2 = generator2.generate( m_fourierSize ); RawPcmData data( *data1 ); data.mixAdd( *data2 ); WaveAnalysis::StftData::Ptr stftData = transform.execute( data ); const WaveAnalysis::SrSpectrum& spectrum = stftData->getSrSpectrum( 0 ); FeatureAlgorithm::SrSpecPeakAlgorithm::Monitor* monitor = 0; if ( iFreq == 0 && iFreqDiff == 2 ) { monitor = new FeatureAlgorithm::SrSpecPeakAlgorithm::Monitor(); } const std::vector< Feature::SrSpecPeak >& peaks = peakAlg.execute( spectrum, monitor ); if ( monitor ) { monitor->createSpectrumPlot( getName() + "/FreqProx/FreqMonitor" ); delete monitor; } getLogger() << Msg::Info << "----------------------------------------" << Msg::EndReq; getLogger() << Msg::Info << "iFreq = " << iFreq << ", iFreqDiff = " << iFreqDiff << Msg::EndReq; getLogger() << Msg::Info << "Truth sinusoid 1: frequency = " << generator1.getFrequency() << ", amplitude = " << generator1.getAmplitude() << Msg::EndReq; getLogger() << Msg::Info << "Truth sinusoid 2: frequency = " << generator2.getFrequency() << ", amplitude = " << generator2.getAmplitude() << Msg::EndReq; RealVector peakAmps( peaks.size() ); for ( size_t iPeak = 0; iPeak < peaks.size(); ++iPeak ) { peakAmps[ iPeak ] = peaks[ iPeak ].getHeight(); } SortCache peakAmpsSc( peakAmps ); if ( peakAmpsSc.getSize() >= 2 ) { double freqEstimate1 = peaks[ peakAmpsSc.getReverseSortedIndex( 0 ) ].getFrequency(); double freqEstimate2 = peaks[ peakAmpsSc.getReverseSortedIndex( 1 ) ].getFrequency(); double errDf1; double errDf2; int estimate1 = 2; int estimate2 = 2; if ( fabs( freqEstimate1 - frequency ) < fabs( freqEstimate1 - frequency2 ) ) { estimate1 = 1; errDf1 = freqEstimate1 - frequency; errDf2 = freqEstimate2 - frequency2; } if ( fabs( freqEstimate2 - frequency ) < fabs( freqEstimate2 - frequency2 ) ) { estimate2 = 1; errDf1 = freqEstimate2 - frequency; errDf2 = freqEstimate1 - frequency2; } if ( estimate1 != estimate2 ) { statusHist.add( PeaksCorrect, 1 ); freqDiffX.push_back( frequencyDifference[ iFreqDiff ] ); freqDiffYMin.push_back( std::min( errDf1, errDf2 ) ); freqDiffYMax.push_back( std::max( errDf1, errDf2 ) ); } else { statusHist.add( PeaksIncorrect, 1 ); } } else { statusHist.add( NotEnoughPeaks, 1 ); } for ( size_t iPeak = 0; iPeak < peaks.size(); ++iPeak ) { double recoAmp = peaks[ iPeak ].getHeight() / m_fourierSize; getLogger() << Msg::Info << "Peak " << iPeak << ": frequency = " << peaks[ iPeak ].getFrequency() << ", amplitude " << recoAmp << Msg::EndReq; } } /// Loop over frequency differences. std::ostringstream plotTitleFreqDifMin; plotTitleFreqDifMin << getName() + "/FreqProx/FreqError" << frequency; gPlotFactory().createPlot( plotTitleFreqDifMin.str() ); gPlotFactory().createGraph( freqDiffX, freqDiffYMin, Qt::blue ); gPlotFactory().createGraph( freqDiffX, freqDiffYMax, Qt::red ); } /// Loop over frequencies. gPlotFactory().createPlot( getName() + "/FroxProx/CategorisedCounts" ); gPlotFactory().createHistogram( statusHist ); }
void TestWritingToFile() throw(Exception) { EXIT_IF_PARALLEL; std::string output_directory = "TestCellBasedPdeHandlerWritingToFile"; // Create a cell population HoneycombMeshGenerator generator(4, 4, 0); MutableMesh<2,2>* p_generating_mesh = generator.GetMesh(); NodesOnlyMesh<2> mesh; mesh.ConstructNodesWithoutMesh(*p_generating_mesh, 1.5); std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, mesh.GetNumNodes()); TS_ASSERT_EQUALS(cells.size(), mesh.GetNumNodes()); NodeBasedCellPopulation<2> cell_population(mesh, cells); cell_population.SetDataOnAllCells("variable", 1.0); // Create a PDE handler object using this cell population CellBasedPdeHandler<2> pde_handler(&cell_population); TS_ASSERT_THROWS_THIS(pde_handler.OpenResultsFiles(output_directory), "Trying to solve a PDE on a cell population that doesn't have a mesh. Try calling UseCoarsePdeMesh()."); // Use a coarse PDE mesh since we are using a node-based cell population AveragedSourcePde<2> pde(cell_population, -0.1); ConstBoundaryCondition<2> bc(1.0); PdeAndBoundaryConditions<2> pde_and_bc(&pde, &bc, false); pde_and_bc.SetDependentVariableName("variable"); pde_handler.AddPdeAndBc(&pde_and_bc); ChastePoint<2> lower(0.0, 0.0); ChastePoint<2> upper(9.0, 9.0); ChasteCuboid<2> cuboid(lower, upper); pde_handler.UseCoarsePdeMesh(3.0, cuboid, true); // For coverage, call SetWriteAverageRadialPdeSolution() prior to output pde_handler.SetWriteAverageRadialPdeSolution("variable", 5, true); // Test that output files are opened correctly pde_handler.OpenResultsFiles(output_directory); FileFinder file_finder(output_directory + "/results.vizcoarsepdesolution", RelativeTo::ChasteTestOutput); TS_ASSERT(file_finder.Exists()); TS_ASSERT(file_finder.IsFile()); FileFinder file_finder2(output_directory + "/radial_dist.dat", RelativeTo::ChasteTestOutput); TS_ASSERT(file_finder2.Exists()); TS_ASSERT(file_finder2.IsFile()); TS_ASSERT_THROWS_NOTHING(pde_handler.CloseResultsFiles()); // For coverage, also test that output files are opened correctly when not using a coarse PDE mesh HoneycombMeshGenerator generator2(5, 5, 0); MutableMesh<2,2>* p_mesh2 = generator2.GetMesh(); std::vector<CellPtr> cells2; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator2; cells_generator2.GenerateBasic(cells2, p_mesh2->GetNumNodes()); MeshBasedCellPopulation<2> cell_population2(*p_mesh2, cells2); cell_population2.SetDataOnAllCells("another variable", 1.0); CellBasedPdeHandler<2> pde_handler2(&cell_population2); pde_handler2.OpenResultsFiles(output_directory); FileFinder file_finder3(output_directory + "/results.vizpdesolution", RelativeTo::ChasteTestOutput); TS_ASSERT(file_finder3.Exists()); TS_ASSERT(file_finder3.IsFile()); pde_handler2.CloseResultsFiles(); }
int main() { // Patients (n), attributes (p), iterations in solving DP (N1), iterations in estimation of ratio (N2); int p = 45; int n = 50; int N1 = 250; int N2 = 250; std::mt19937 generator1 (61245); std::mt19937 generator2 (16746); std::mt19937 generator3 (27351); std::mt19937 generator4 (66459); std::mt19937 generator5 (12612); std::mt19937 generator6 (16326); std::mt19937 generator7 (86733); std::normal_distribution <double> nd(0.0, 1.0); std::chi_squared_distribution <double> xs(p - 2); //R is Cholesky factorization of Covar matrix //mu is vector of patient attribute means Eigen::MatrixXd s(p-1,p-1); Eigen::MatrixXd si(p-1,p-1); Eigen::MatrixXd zee(n,p-1); Eigen::MatrixXd Z(n,p-1); Eigen::MatrixXd Z2(n,p); //Update mu as necessary Eigen::VectorXd mu = Eigen::VectorXd::Zero(p-1); //Generates matrix of standard normals, then uses cholesky factorization to get correct covar matrix for (int i = 0; i < n; i++){ for (int j = 0; j < p-1; j++){ zee(i,j) = nd(generator1); } } for (int i = 0; i < p-1; i++){ for (int j = 0; j < p-1; j++){ if (i==j) { s(i,j) = 1.0; } else { s(i,j) = 0.1; } } } si = s.inverse(); Eigen::LLT<Eigen::MatrixXd> lltOfS(s); Eigen::MatrixXd R = lltOfS.matrixL(); double temp = 0; //Z2 is matrix of patient attributes (n x p) Z = zee*R; for (int i = 0; i < n; i++){ for (int j = 0; j < p; j++){ if(j > 0){ Z2(i,j) = Z(i,j-1) + mu(j-1); } else{ Z2(i,j) = 1; } } } //Eta + Xi computation double eta1 [N1]; double xi1 [N1]; double eta2 [N1]; double xi2 [N1]; for (int i = 0; i < N1; i++){ eta1[i] = nd(generator3)+2; xi1[i] = xs(generator4); eta2[i] = nd(generator6)-2; xi2[i] = xs(generator7); } //Solving 2-D DP using mesh double M = 2000.0; double delta = 0.2; int steps = ceil(M/delta)+1; DP table(n, delta, M); //syntax helpers double lambda = 0; int m = 0; double lambda_up = 0; double lambda_down = 0; double roundup_plus = 0; double rounddown_plus = 0; double roundup_minus = 0; double rounddown_minus = 0; double distdown_minus = 0; double distup_minus = 0; double distdown_plus = 0; double distup_plus = 0; double plus = 0; double minus = 0; double plus2 = 0; double minus2 = 0; int screwups = 0; //Boundary condition for (int i = 0; i < 2*n + 1; i++){ for (int j = 0; j < steps;j++){ m = i-n; lambda = delta*j; table.set(0, i, j, pow(m, 2) + lambda); } } //Solving mesh for (int l = 1;l < n; l++){ std::cout << l << "\n"; for (int i = l; i < 2*n+1-l; i++){ //under my indexing, l + k = n m = i-n; for (int j = 0; j < steps; j++){ lambda = delta*j; temp = 0; for (int iter = 0; iter < N1; iter++){ lambda_up = pow(sqrt(lambda)+eta1[iter],2)+xi1[iter]; lambda_down = pow(sqrt(lambda)-eta1[iter],2)+xi1[iter]; if (lambda_down > M){ lambda_down = M; } if (lambda_up > M){ lambda_up = M; } roundup_plus = ceil(lambda_up/delta); rounddown_plus = floor(lambda_up/delta); distdown_plus = lambda_up - rounddown_plus*delta; distup_plus = roundup_plus*delta - lambda_up; roundup_minus = ceil(lambda_down/delta); rounddown_minus = floor(lambda_down/delta); distdown_minus = lambda_down - rounddown_minus*delta; distup_minus = roundup_minus*delta - lambda_down; try{ plus = (1/delta)*(distup_plus*table.at(l-1, i+1, rounddown_plus) + distdown_plus*table.at(l-1, i+1, roundup_plus)); minus = (1/delta)*(distup_minus*table.at(l-1,i-1,rounddown_minus) + distdown_minus*table.at(l-1,i-1,roundup_minus)); } catch (const std::out_of_range& e){ std::cout << "roundup/down_plus " << roundup_plus << ", " << rounddown_plus << "\n"; std::cout << "roundup/down_minus " << roundup_minus << ", " << rounddown_minus << "\n"; std::cout << "Line 151 \n"; return 0; } lambda_up = pow(sqrt(lambda)+eta2[iter],2)+xi2[iter]; lambda_down = pow(sqrt(lambda)-eta2[iter],2)+xi2[iter]; if (lambda_down > M){ lambda_down = M; } if (lambda_up > M){ lambda_up = M; } roundup_plus = ceil(lambda_up/delta); rounddown_plus = floor(lambda_up/delta); distdown_plus = lambda_up - rounddown_plus*delta; distup_plus = roundup_plus*delta - lambda_up; roundup_minus = ceil(lambda_down/delta); rounddown_minus = floor(lambda_down/delta); distdown_minus = lambda_down - rounddown_minus*delta; distup_minus = roundup_minus*delta - lambda_down; try{ plus += (1/delta)*(distup_plus*table.at(l-1, i+1, rounddown_plus) + distdown_plus*table.at(l-1, i+1, roundup_plus)); minus += (1/delta)*(distup_minus*table.at(l-1,i-1,rounddown_minus) + distdown_minus*table.at(l-1,i-1,roundup_minus)); } catch (const std::out_of_range& e){ std::cout << "roundup/down_plus " << roundup_plus << ", " << rounddown_plus << "\n"; std::cout << "roundup/down_minus " << roundup_minus << ", " << rounddown_minus << "\n"; std::cout << "Line 151 \n"; return 0; } temp = temp*iter/(iter+1) + std::min(plus,minus)/(iter+1); /*if(temp < 0){ std::cout << lambda_down << " " << lambda_up << "\n"; std::cout << distdown_plus << " " << distup_plus << "\n"; std::cout << distdown_minus << " " << distup_minus << "\n"; return 0; }*/ } try{ table.set(l,i,j,temp); } catch (const std::out_of_range& e){ std::cout << "(" << l << ", " << i << ", " << j <<") \n"; } } } } char result[ PATH_MAX ]; ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX ); std::string name = std::string( result, (count > 0) ? count : 0); std::string extension = ".csv"; name.append(extension); std::ofstream outputFile; outputFile.open(name); //for (int l = 0; l < n; l++){ for (int l = 0; l < n; l++){ for (int i=0; i < 2*n+1;i++){ for (int j=0; j < 1; j++){ outputFile << table.at(l,i,j) << ", "; } //outputFile << "\n"; } outputFile << "\n"; } outputFile.close(); return 0; //Vs Naive random allocation //Eff = x^T P_Z x where x is allocations, P_Z = I - Z(Z^T Z)^(-1) Z^T Eigen::MatrixXd PZ; Eigen::MatrixXd I = Eigen::MatrixXd::Identity(n,n); Eigen::MatrixXd Z2I; //Generates matrix of standard normals, then uses cholesky factorization to get correct covar matrix //Vector of n/2 1's and -1's int rand_x[n]; for (int i = 0; i < n; i++){ rand_x[i] = -1 + 2*floor(2*i/n); } std::vector <int> myvector (rand_x, rand_x+n); Eigen::VectorXd random_x(n); Eigen::VectorXd dp_x(n); double eff_r = 0; double eff_dp = 0; double eff = 0; //Tracks variable Delta as in paper Eigen::VectorXd var_Delta(p-1); var_Delta.setZero(); Eigen::VectorXd var_Delta_up(p-1); Eigen::VectorXd var_Delta_down(p-1); Eigen::MatrixXd condition(n,n); //Used to prevent floating point problems int var_delta; double mahalanobis_plus = 0; double mahalanobis_minus = 0; //Eigen::EigenSolver<Eigen::MatrixXd> es; //Large loop to test policies for (int asdf = 0; asdf < N2; asdf++){ //std::cout << "asdf = " << asdf << "\n"; var_delta = n; var_Delta.setZero(); for (int i = 0; i < n; i++){ for (int j = 0; j < p-1; j++){ zee(i,j) = nd(generator1); } } //Z is matrix of patient attributes (n x p) Z = zee*R; for (int i = 0; i < n; i++){ for (int j = 0; j < p; j++){ if(j > 0){ Z2(i,j) = Z(i,j-1) + mu(j-1); } else{ Z2(i,j) = 1; } } } Z2I = Z2.transpose()*Z2; PZ = I - Z2*(Z2I.inverse())*Z2.transpose(); //es.compute(PZ, false); //temp = 0; //for (int i = 0; i < n; i++){ // if (temp > (double)(es.eigenvalues()(i,0).real())){ // temp = (double)(es.eigenvalues()(i,0).real()); // } //} //PZ = PZ + Eigen::MatrixXd::Identity(n,n)*temp; //This is where randomized sampling is done for (int i = 0; i < N1; i++){ std::random_shuffle ( myvector.begin(), myvector.end()); for (int j = 0; j < n; j++){ random_x(j) = myvector[j]; } temp = random_x.transpose() * PZ * random_x; eff_r = eff_r*i/(i+1) + temp/(i+1); } //This is where we do "optimal" sampling for (int i = 0; i < n; i++){ std::cout << Z2.block(i,1,1,p-1) << "\n"; var_Delta_up = var_Delta + Z2.block(i,1,1,p-1).transpose(); std::cout << var_Delta_up.transpose() << "\n"; var_Delta_down = var_Delta - Z2.block(i,1,1,p-1).transpose(); std::cout << var_Delta_down.transpose() << "\n"; mahalanobis_plus = var_Delta_up.transpose()*si*var_Delta_up; std::cout << mahalanobis_plus << "\n"; roundup_plus = ceil(mahalanobis_plus/delta); rounddown_plus = floor(mahalanobis_plus/delta ); distup_plus = roundup_plus*delta - mahalanobis_plus; distdown_plus = mahalanobis_plus - rounddown_plus*delta; //std::cout << var_delta << "\n"; //std::cout << rounddown_plus << " " << roundup_plus << "\n"; //std::cout << "(" << n-i-1 << "," << var_delta+1 << ", " << rounddown_plus << ") \n"; //std::cout << "plus done \n"; mahalanobis_minus = var_Delta_down.transpose()*si*var_Delta_down; roundup_minus = ceil(mahalanobis_minus/delta ); rounddown_minus = floor(mahalanobis_minus/delta); distup_minus = roundup_minus*delta - mahalanobis_minus; distdown_minus = mahalanobis_minus - rounddown_minus*delta; //std::cout << "(" << n-i-1 << "," << var_delta-1 << ", " << rounddown_plus << ") \n"; try{ plus = (1/delta)*(distup_plus*table.at(n-1-i,var_delta+1, rounddown_plus) + distdown_plus*table.at(n-1-i,var_delta+1,roundup_plus)); minus = (1/delta)*(distup_minus*table.at(n-1-i,var_delta-1, rounddown_minus) + distdown_minus*table.at(n-1-i,var_delta-1,roundup_minus)); if (minus > plus){ var_delta++; var_Delta = var_Delta_up; dp_x(i) = 1; } else{ var_delta--; var_Delta = var_Delta_down; dp_x(i) = -1; } } catch (const std::out_of_range& e){ std::cout << "mahalanobis_plus = " << mahalanobis_plus << "\n"; std::cout << "mahalanobis_minus = " << mahalanobis_minus << "\n"; std::cout << "distdown/up plus =" << distdown_plus << ", " << distup_plus << "\n"; std::cout << "distdown/up minus =" << distdown_minus << ", " << distup_minus << "\n"; std::cout << "line 273 \n"; std::cout << asdf << "\n"; screwups++; } std::cout << "Press any key to continue."; std::cin.get(); } eff_dp = dp_x.transpose()*PZ*dp_x; std::cout << eff_r << ", " << eff_dp << "\n"; temp += eff_dp/eff_r; eff = eff*asdf/(asdf+1) + (eff_dp/eff_r)/(asdf+1); } std::cout << temp/(N1-screwups) << "\n"; std::cout << "screwups = " << screwups << "\n"; std::cout << eff << "\n"; //std::cout << "\n" << PZ << "\n"; //std::cout << "\n" << eff_r << "\n \n" << eff_dp << "\n"; //std::cout << "\n" << dp_x << "\n \n" << dp_x.transpose()*PZ*dp_x; //Eigen::EigenSolver<Eigen::MatrixXd> es; //es.compute(PZ); //std::cout << "\n" << es.eigenvalues(); }
void TestValidate() throw (Exception) { // Create a simple Potts mesh PottsMeshGenerator<2> generator(4, 2, 2, 4, 2, 2); PottsMesh<2>* p_mesh = generator.GetMesh(); // Create cells std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, p_mesh->GetNumElements()-1); std::vector<unsigned> cell_location_indices; for (unsigned i=0; i<cells.size(); i++) { cell_location_indices.push_back(i); } // This should throw an exception as the number of cells does not equal the number of elements std::vector<CellPtr> cells_copy(cells); TS_ASSERT_THROWS_THIS(PottsBasedCellPopulation<2> cell_population(*p_mesh, cells_copy), "At time 0, Element 3 does not appear to have a cell associated with it"); MAKE_PTR(WildTypeCellMutationState, p_state); MAKE_PTR(StemCellProliferativeType, p_stem_type); FixedDurationGenerationBasedCellCycleModel* p_model = new FixedDurationGenerationBasedCellCycleModel(); CellPtr p_cell1(new Cell(p_state, p_model)); p_cell1->SetCellProliferativeType(p_stem_type); double birth_time = 0.0 - p_mesh->GetNumElements()-1; p_cell1->SetBirthTime(birth_time); cells.push_back(p_cell1); cell_location_indices.push_back(p_mesh->GetNumElements()-1); // This should pass as the number of cells equals the number of elements std::vector<CellPtr> cells_copy2(cells); TS_ASSERT_THROWS_NOTHING(PottsBasedCellPopulation<2> cell_population(*p_mesh, cells_copy2)); // Create cell population PottsBasedCellPopulation<2> cell_population(*p_mesh, cells); // Check correspondence between elements and cells for (PottsMesh<2>::PottsElementIterator iter = p_mesh->GetElementIteratorBegin(); iter != p_mesh->GetElementIteratorEnd(); ++iter) { std::set<unsigned> expected_node_indices; unsigned expected_index = iter->GetIndex(); for (unsigned i=0; i<iter->GetNumNodes(); i++) { expected_node_indices.insert(iter->GetNodeGlobalIndex(i)); } std::set<unsigned> actual_node_indices; unsigned elem_index = iter->GetIndex(); CellPtr p_cell = cell_population.GetCellUsingLocationIndex(elem_index); PottsElement<2>* p_actual_element = cell_population.GetElementCorrespondingToCell(p_cell); unsigned actual_index = p_actual_element->GetIndex(); for (unsigned i=0; i<p_actual_element->GetNumNodes(); i++) { actual_node_indices.insert(p_actual_element->GetNodeGlobalIndex(i)); } TS_ASSERT_EQUALS(actual_index, expected_index); TS_ASSERT_EQUALS(actual_node_indices, expected_node_indices); } // Create another simple potts-based mesh PottsMeshGenerator<2> generator2(4, 2, 2, 4, 2, 2); PottsMesh<2>* p_mesh2 = generator2.GetMesh(); // Create cells std::vector<CellPtr> cells2; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator2; cells_generator2.GenerateBasic(cells2, p_mesh2->GetNumElements()+1); std::vector<unsigned> cell_location_indices2; for (unsigned i=0; i<cells2.size(); i++) { cell_location_indices2.push_back(i%p_mesh2->GetNumElements()); // Element 0 will have 2 cells } // This should throw a never-reached exception as the number of cells // does not equal the number of elements TS_ASSERT_THROWS_THIS(PottsBasedCellPopulation<2> cell_population2(*p_mesh2, cells2, false, true, cell_location_indices2), "At time 0, Element 0 appears to have 2 cells associated with it"); }