void main(void) { int c1 ; int i2 ; { c1 = 0; ep12 = __VERIFIER_nondet__Bool(); ep13 = __VERIFIER_nondet__Bool(); ep14 = __VERIFIER_nondet__Bool(); ep21 = __VERIFIER_nondet__Bool(); ep23 = __VERIFIER_nondet__Bool(); ep24 = __VERIFIER_nondet__Bool(); ep31 = __VERIFIER_nondet__Bool(); ep32 = __VERIFIER_nondet__Bool(); ep34 = __VERIFIER_nondet__Bool(); ep41 = __VERIFIER_nondet__Bool(); ep42 = __VERIFIER_nondet__Bool(); ep43 = __VERIFIER_nondet__Bool(); id1 = __VERIFIER_nondet_char(); r1 = __VERIFIER_nondet_char(); st1 = __VERIFIER_nondet_char(); nl1 = __VERIFIER_nondet_char(); m1 = __VERIFIER_nondet_char(); max1 = __VERIFIER_nondet_char(); mode1 = __VERIFIER_nondet__Bool(); newmax1 = __VERIFIER_nondet__Bool(); id2 = __VERIFIER_nondet_char(); r2 = __VERIFIER_nondet_char(); st2 = __VERIFIER_nondet_char(); nl2 = __VERIFIER_nondet_char(); m2 = __VERIFIER_nondet_char(); max2 = __VERIFIER_nondet_char(); mode2 = __VERIFIER_nondet__Bool(); newmax2 = __VERIFIER_nondet__Bool(); id3 = __VERIFIER_nondet_char(); r3 = __VERIFIER_nondet_char(); st3 = __VERIFIER_nondet_char(); nl3 = __VERIFIER_nondet_char(); m3 = __VERIFIER_nondet_char(); max3 = __VERIFIER_nondet_char(); mode3 = __VERIFIER_nondet__Bool(); newmax3 = __VERIFIER_nondet__Bool(); id4 = __VERIFIER_nondet_char(); r4 = __VERIFIER_nondet_char(); st4 = __VERIFIER_nondet_char(); nl4 = __VERIFIER_nondet_char(); m4 = __VERIFIER_nondet_char(); max4 = __VERIFIER_nondet_char(); mode4 = __VERIFIER_nondet__Bool(); newmax4 = __VERIFIER_nondet__Bool(); i2 = init(); __VERIFIER_assume(i2); p12_old = nomsg; p12_new = nomsg; p13_old = nomsg; p13_new = nomsg; p14_old = nomsg; p14_new = nomsg; p21_old = nomsg; p21_new = nomsg; p23_old = nomsg; p23_new = nomsg; p24_old = nomsg; p24_new = nomsg; p31_old = nomsg; p31_new = nomsg; p32_old = nomsg; p32_new = nomsg; p34_old = nomsg; p34_new = nomsg; p41_old = nomsg; p41_new = nomsg; p42_old = nomsg; p42_new = nomsg; p43_old = nomsg; p43_new = nomsg; i2 = 0; while (i2 < 8) { { node1(); node2(); node3(); node4(); p12_old = p12_new; p12_new = nomsg; p13_old = p13_new; p13_new = nomsg; p14_old = p14_new; p14_new = nomsg; p21_old = p21_new; p21_new = nomsg; p23_old = p23_new; p23_new = nomsg; p24_old = p24_new; p24_new = nomsg; p31_old = p31_new; p31_new = nomsg; p32_old = p32_new; p32_new = nomsg; p34_old = p34_new; p34_new = nomsg; p41_old = p41_new; p41_new = nomsg; p42_old = p42_new; p42_new = nomsg; p43_old = p43_new; p43_new = nomsg; c1 = check(); assert(c1); i2 ++; } } } }
void main(void) { int c1 ; int i2 ; { c1 = 0; r1 = __VERIFIER_nondet_char(); id1 = __VERIFIER_nondet_char(); st1 = __VERIFIER_nondet_char(); send1 = __VERIFIER_nondet_msg_t(); mode1 = __VERIFIER_nondet__Bool(); alive1 = __VERIFIER_nondet__Bool(); id2 = __VERIFIER_nondet_char(); st2 = __VERIFIER_nondet_char(); send2 = __VERIFIER_nondet_msg_t(); mode2 = __VERIFIER_nondet__Bool(); alive2 = __VERIFIER_nondet__Bool(); id3 = __VERIFIER_nondet_char(); st3 = __VERIFIER_nondet_char(); send3 = __VERIFIER_nondet_msg_t(); mode3 = __VERIFIER_nondet__Bool(); alive3 = __VERIFIER_nondet__Bool(); id4 = __VERIFIER_nondet_char(); st4 = __VERIFIER_nondet_char(); send4 = __VERIFIER_nondet_msg_t(); mode4 = __VERIFIER_nondet__Bool(); alive4 = __VERIFIER_nondet__Bool(); id5 = __VERIFIER_nondet_char(); st5 = __VERIFIER_nondet_char(); send5 = __VERIFIER_nondet_msg_t(); mode5 = __VERIFIER_nondet__Bool(); alive5 = __VERIFIER_nondet__Bool(); i2 = init(); __VERIFIER_assume(i2); p1_old = nomsg; p1_new = nomsg; p2_old = nomsg; p2_new = nomsg; p3_old = nomsg; p3_new = nomsg; p4_old = nomsg; p4_new = nomsg; p5_old = nomsg; p5_new = nomsg; i2 = 0; while (1) { { node1(); node2(); node3(); node4(); node5(); p1_old = p1_new; p1_new = nomsg; p2_old = p2_new; p2_new = nomsg; p3_old = p3_new; p3_new = nomsg; p4_old = p4_new; p4_new = nomsg; p5_old = p5_new; p5_new = nomsg; c1 = check(); assert(c1); } } } }
int run_main (int, ACE_TCHAR *[]) { int r; int retval = 0; unsigned k; MyNode node (1); ACE_START_TEST (ACE_TEXT ("Unbounded_Set_Test")); ACE_Unbounded_Set<MyNode> ubs; if (ubs.size () != 0) { ACE_ERROR ((LM_ERROR, "Error: ubs.size () != 0\n")); retval = -1; } if (!ubs.is_empty ()) { ACE_ERROR ((LM_ERROR, "Error: !ubs.is_empty ()\n")); retval = -1; } // Insert a value. Immediately remove it. r = ubs.insert (node); if (r != 0) { ACE_ERROR ((LM_ERROR, "Error: r != 0\n")); retval = -1; } if (ubs.size () != 1) { ACE_ERROR ((LM_ERROR, "Error: ubs.size () != 1\n")); retval = -1; } r = ubs.remove (node); if (r != 0) { ACE_ERROR ((LM_ERROR, "Error: r != 0\n")); retval = -1; } if (ubs.size () != 0) { ACE_ERROR ((LM_ERROR, "Error: ubs.size () != 0\n")); retval = -1; } // Insert several different values. for (node.k = 1; node.k <= 5; node.k++) { r = ubs.insert (node); if (r != 0) { ACE_ERROR ((LM_ERROR, "Error: r != 0\n")); retval = -1; } if (ubs.size () != node.k) { ACE_ERROR ((LM_ERROR, "Error: ubs.size () != node.k\n")); retval = -1; } } // Test assigment of sets. // To do that, we also test some of the iterator methods. typedef ACE_Unbounded_Set<MyNode> MySet; MySet ubs2 = ubs; // Test a typedef of a set. if (ubs2.size() != ubs.size()) { ACE_ERROR ((LM_ERROR, "Error: ubs2.size() != ubs.size()\n")); retval = -1; } { MySet::ITERATOR it1 (ubs); MySet::iterator it2 (ubs2); for (k = 1; k <= 5; k++) { if (it1.done ()) { ACE_ERROR ((LM_ERROR, "Error: it1.done ()\n")); retval = -1; } if (it2.done ()) { ACE_ERROR ((LM_ERROR, "Error: it2.done ()\n")); retval = -1; } MyNode n1 = *it1; MyNode n2 = *it2; if (!(n1 == n2)) { ACE_ERROR ((LM_ERROR, "Error: !(n1 == n2)\n")); retval = -1; } it1.advance (); it2.advance (); } if (!it1.done ()) { ACE_ERROR ((LM_ERROR, "Error: !it1.done ()\n")); retval = -1; } if (!it2.done ()) { ACE_ERROR ((LM_ERROR, "Error: !it2.done ()\n")); retval = -1; } // Verify that a set may be emptied while an iterator on the set is // in-scope but inactive: ubs.reset (); // Restore original set from ubs2 ubs = ubs2; } // Selective deletion of elements and element retrieval. { MySet::iterator it (ubs2); int deleted = 0; while (! it.done ()) { MyNode n = *it; it.advance (); /* Being friendly here: Move the iterator on so that element removal does not interfere with the current iterator position. The less friendly case, removal under the current iterator position, is below. */ if (n.k % 2 == 1) { r = ubs2.remove (n); deleted++; } } if (ubs2.size () + deleted != ubs.size()) { ACE_ERROR ((LM_ERROR, "Error: ubs2.size () + deleted != ubs.size()\n")); retval = -1; } MyNode node2 (2); if (ubs2.find (node2) != 0) { ACE_ERROR ((LM_ERROR, "Error: ubs2.find (node2) != 0\n")); retval = -1; } MyNode node3 (3); if (ubs2.find (node3) == 0) { ACE_ERROR ((LM_ERROR, "Error: ubs2.find (node3) == 0\n")); retval = -1; } ubs2.insert (node3); } size_t s = count_const_set (ubs); if (s != ubs.size ()) { ACE_ERROR ((LM_ERROR, "Error: s != ubs.size ()\n")); retval = -1; } ACE_Unbounded_Set<MyNode> ubs_insert; MyNode node4 (4); if (ubs_insert.insert (node4) != 0) { ACE_ERROR ((LM_ERROR, "Error: insert node4 failed\n")); retval = -1; } if (ubs_insert.insert (node4) != 1) { ACE_ERROR ((LM_ERROR, "Error: insert node4 didn't return 1\n")); retval = -1; } ACE_END_TEST; return retval; }
int run_main (int, ACE_TCHAR *[]) { int r; unsigned k; MyNode node (1); ACE_START_TEST (ACE_TEXT ("Unbounded_Set_Test")); ACE_Unbounded_Set<MyNode> ubs; ACE_ASSERT (ubs.size () == 0); // Insert a value. Immediately remove it. r = ubs.insert (node); ACE_ASSERT (r == 0); ACE_ASSERT (ubs.size () == 1); r = ubs.remove (node); ACE_ASSERT (r == 0); ACE_ASSERT (ubs.size () == 0); // Insert several different values. for (node.k = 1; node.k <= 5; node.k++) { r = ubs.insert (node); ACE_ASSERT (r == 0); ACE_ASSERT (ubs.size () == node.k); } // Test assigment of sets. // To do that, we also test some of the iterator methods. typedef ACE_Unbounded_Set<MyNode> MySet; MySet ubs2 = ubs; // Test a typedef of a set. ACE_ASSERT (ubs2.size() == ubs.size()); { MySet::ITERATOR it1 (ubs); MySet::iterator it2 (ubs2); for (k = 1; k <= 5; k++) { ACE_ASSERT (! it1.done ()); ACE_ASSERT (! it2.done ()); MyNode n1 = *it1; MyNode n2 = *it2; ACE_ASSERT (n1 == n2); it1.advance (); it2.advance (); } ACE_ASSERT (it1.done ()); ACE_ASSERT (it2.done ()); // Verify that a set may be emptied while an iterator on the set is // in-scope but inactive: ubs.reset (); // Restore original set from ubs2 ubs = ubs2; } // Selective deletion of elements and element retrieval. { MySet::iterator it (ubs2); int deleted = 0; while (! it.done ()) { MyNode n = *it; it.advance (); /* Being friendly here: Move the iterator on so that element removal does not interfere with the current iterator position. The less friendly case, removal under the current iterator position, is below. */ if (n.k % 2 == 1) { r = ubs2.remove (n); deleted++; } } ACE_ASSERT (ubs2.size () + deleted == ubs.size()); MyNode node2 (2); ACE_ASSERT (ubs2.find (node2) == 0); MyNode node3 (3); ACE_ASSERT (ubs2.find (node3) != 0); ubs2.insert (node3); } size_t s = count_const_set (ubs); ACE_ASSERT (s == ubs.size ()); // Test deletion under the cursor. // This is the regression test for Bugzilla bug 1460. { MySet::iterator end = ubs2.end (); for (MySet::iterator i = ubs2.begin (); i != end; i++) { r = ubs2.remove (*i); ACE_ASSERT (r == 0); } ACE_ASSERT (ubs2.size () == 0); } ACE_ASSERT (ubs2.is_empty ()); ACE_END_TEST; return 0; }
vector< vector < set < vector< vector<int> > > > > myGraph::findPathforTwoNodes(int pid1, int type1, int id1, int pid2, int type2, int id2) { vector<vector<int>> pathVector; vector< vector < set < vector< vector<int> > > > > linkededge; //vertexInfo //... //Graph //find node set vector<int> node1(3,-1), node2(3,-1), edge_t(2,-1); vector<vector<int>> AEdge; AEdge.push_back(node1), AEdge.push_back(node2); int start, end; node1[0] = pid1, node1[1] = type1, node1[2] = id1; node2[0] = pid2, node2[1] = type2, node2[2] = id2; start = findNodeID(node1, nodeVector); end = findNodeID(node2, nodeVector); if(start<0 || end<0) return linkededge; findAllPathesBetweenTwoNodes(start, end, totalNode, totalEdge, _Graph, pathVector); /*findAllPathes(18, 20, totalnode, totaledge, GRAPH, pathVector); findAllPathes(1, 10, totalnode, totaledge, GRAPH, pathVector); findAllPathes(15, 20, totalnode, totaledge, GRAPH, pathVector); findAllPathes(25, 20, totalnode, totaledge, GRAPH, pathVector); */ //if(pid1 >= linkededge.size()) linkededge.resize(pid1+1); //if(pid2 >= linkededge.size()) linkededge.resize(pid2+1); /*if(m_pathwayID>=linkedProtein.size()) linkedProtein.resize(m_pathwayID+1); if(m_pathwayID>=linkedSmallMolecule.size()) linkedSmallMolecule.resize(m_pathwayID+1); if(m_pathwayID>=linkedComplex.size()) linkedComplex.resize(m_pathwayID+1); if(m_pathwayID>=linkedDna.size()) linkedDna.resize(m_pathwayID+1); if(m_pathwayID>=linkedReaction.size()) linkedReaction.resize(m_pathwayID+1); if(m_pathwayID>=linkedANode.size()) linkedANode.resize(m_pathwayID+1); if(m_pathwayID>=linkedCompartment.size()) linkedCompartment.resize(m_pathwayID+1); if(m_pathwayID>=linkedPathway.size()) linkedPathway.resize(m_pathwayID+1);*/ for(int i=0; i<pathVector.size(); ++i) { set < vector < vector<int> > > path; set <int> pids; for(int j=0; j<pathVector[i].size()-1; ++j) { int id1=pathVector[i][j], id2=pathVector[i][j+1]; AEdge[0] = nodeVector[id1]; AEdge[1]= nodeVector[id2]; path.insert(AEdge); pids.insert(AEdge[0][0]); pids.insert(AEdge[1][0]); } for(set<int>::iterator it=pids.begin(); it!=pids.end(); it++) { int ptid = *it; if(ptid>=linkededge.size()) linkededge.resize(ptid+1); linkededge[ptid].push_back(path); } } //getGraphToBePaint(); return linkededge; }
int main(void) { int c1 ; int i2 ; { c1 = 0; ep12 = __VERIFIER_nondet__Bool(); ep13 = __VERIFIER_nondet__Bool(); ep21 = __VERIFIER_nondet__Bool(); ep23 = __VERIFIER_nondet__Bool(); ep31 = __VERIFIER_nondet__Bool(); ep32 = __VERIFIER_nondet__Bool(); id1 = __VERIFIER_nondet_char(); r1 = __VERIFIER_nondet_char(); st1 = __VERIFIER_nondet_char(); nl1 = __VERIFIER_nondet_char(); m1 = __VERIFIER_nondet_char(); max1 = __VERIFIER_nondet_char(); mode1 = __VERIFIER_nondet__Bool(); id2 = __VERIFIER_nondet_char(); r2 = __VERIFIER_nondet_char(); st2 = __VERIFIER_nondet_char(); nl2 = __VERIFIER_nondet_char(); m2 = __VERIFIER_nondet_char(); max2 = __VERIFIER_nondet_char(); mode2 = __VERIFIER_nondet__Bool(); id3 = __VERIFIER_nondet_char(); r3 = __VERIFIER_nondet_char(); st3 = __VERIFIER_nondet_char(); nl3 = __VERIFIER_nondet_char(); m3 = __VERIFIER_nondet_char(); max3 = __VERIFIER_nondet_char(); mode3 = __VERIFIER_nondet__Bool(); i2 = init(); __VERIFIER_assume(i2); p12_old = nomsg; p12_new = nomsg; p13_old = nomsg; p13_new = nomsg; p21_old = nomsg; p21_new = nomsg; p23_old = nomsg; p23_new = nomsg; p31_old = nomsg; p31_new = nomsg; p32_old = nomsg; p32_new = nomsg; i2 = 0; while (1) { { node1(); node2(); node3(); p12_old = p12_new; p12_new = nomsg; p13_old = p13_new; p13_new = nomsg; p21_old = p21_new; p21_new = nomsg; p23_old = p23_new; p23_new = nomsg; p31_old = p31_new; p31_new = nomsg; p32_old = p32_new; p32_new = nomsg; c1 = check(); assert(c1); } } } return 0; }
int main(void) { int c1 ; int i2 ; { c1 = 0; r1 = __VERIFIER_nondet_uchar(); id1 = __VERIFIER_nondet_char(); st1 = __VERIFIER_nondet_char(); send1 = __VERIFIER_nondet_char(); mode1 = __VERIFIER_nondet_bool(); id2 = __VERIFIER_nondet_char(); st2 = __VERIFIER_nondet_char(); send2 = __VERIFIER_nondet_char(); mode2 = __VERIFIER_nondet_bool(); id3 = __VERIFIER_nondet_char(); st3 = __VERIFIER_nondet_char(); send3 = __VERIFIER_nondet_char(); mode3 = __VERIFIER_nondet_bool(); id4 = __VERIFIER_nondet_char(); st4 = __VERIFIER_nondet_char(); send4 = __VERIFIER_nondet_char(); mode4 = __VERIFIER_nondet_bool(); id5 = __VERIFIER_nondet_char(); st5 = __VERIFIER_nondet_char(); send5 = __VERIFIER_nondet_char(); mode5 = __VERIFIER_nondet_bool(); id6 = __VERIFIER_nondet_char(); st6 = __VERIFIER_nondet_char(); send6 = __VERIFIER_nondet_char(); mode6 = __VERIFIER_nondet_bool(); id7 = __VERIFIER_nondet_char(); st7 = __VERIFIER_nondet_char(); send7 = __VERIFIER_nondet_char(); mode7 = __VERIFIER_nondet_bool(); i2 = init(); __VERIFIER_assume(i2); p1_old = nomsg; p1_new = nomsg; p2_old = nomsg; p2_new = nomsg; p3_old = nomsg; p3_new = nomsg; p4_old = nomsg; p4_new = nomsg; p5_old = nomsg; p5_new = nomsg; p6_old = nomsg; p6_new = nomsg; p7_old = nomsg; p7_new = nomsg; i2 = 0; while (1) { { node1(); node2(); node3(); node4(); node5(); node6(); node7(); p1_old = p1_new; p1_new = nomsg; p2_old = p2_new; p2_new = nomsg; p3_old = p3_new; p3_new = nomsg; p4_old = p4_new; p4_new = nomsg; p5_old = p5_new; p5_new = nomsg; p6_old = p6_new; p6_new = nomsg; p7_old = p7_new; p7_new = nomsg; c1 = check(); assert(c1); } } } return 0; }
double length () const { return norm(node1().position() - node2().position()); }
TEST_F(MutateTests, StressTests) { auto &txn_manager = concurrency::OptimisticTxnManager::GetInstance(); auto txn = txn_manager.BeginTransaction(); std::unique_ptr<executor::ExecutorContext> context( new executor::ExecutorContext(txn)); auto testing_pool = TestingHarness::GetInstance().GetTestingPool(); // Create insert node for this test. storage::DataTable *table = ExecutorTestsUtil::CreateTable(); // Pass through insert executor. storage::Tuple *tuple; tuple = ExecutorTestsUtil::GetNullTuple(table, testing_pool); auto project_info = MakeProjectInfoFromTuple(tuple); planner::InsertPlan node(table, project_info); executor::InsertExecutor executor(&node, context.get()); try { executor.Execute(); } catch (ConstraintException &ce) { LOG_ERROR("%s", ce.what()); } delete tuple; tuple = ExecutorTestsUtil::GetTuple(table, ++tuple_id, testing_pool); project_info = MakeProjectInfoFromTuple(tuple); planner::InsertPlan node2(table, project_info); executor::InsertExecutor executor2(&node2, context.get()); executor2.Execute(); try { executor2.Execute(); } catch (ConstraintException &ce) { LOG_ERROR("%s", ce.what()); } delete tuple; txn_manager.CommitTransaction(); LaunchParallelTest(1, InsertTuple, table, testing_pool); LOG_TRACE(table->GetInfo().c_str()); LOG_INFO("---------------------------------------------"); // LaunchParallelTest(1, UpdateTuple, table); // LOG_TRACE(table->GetInfo().c_str()); LOG_INFO("---------------------------------------------"); LaunchParallelTest(1, DeleteTuple, table); LOG_TRACE(table->GetInfo().c_str()); // PRIMARY KEY std::vector<catalog::Column> columns; columns.push_back(ExecutorTestsUtil::GetColumnInfo(0)); catalog::Schema *key_schema = new catalog::Schema(columns); storage::Tuple *key1 = new storage::Tuple(key_schema, true); storage::Tuple *key2 = new storage::Tuple(key_schema, true); key1->SetValue(0, ValueFactory::GetIntegerValue(10), nullptr); key2->SetValue(0, ValueFactory::GetIntegerValue(100), nullptr); delete key1; delete key2; delete key_schema; // SEC KEY columns.clear(); columns.push_back(ExecutorTestsUtil::GetColumnInfo(0)); columns.push_back(ExecutorTestsUtil::GetColumnInfo(1)); key_schema = new catalog::Schema(columns); storage::Tuple *key3 = new storage::Tuple(key_schema, true); storage::Tuple *key4 = new storage::Tuple(key_schema, true); key3->SetValue(0, ValueFactory::GetIntegerValue(10), nullptr); key3->SetValue(1, ValueFactory::GetIntegerValue(11), nullptr); key4->SetValue(0, ValueFactory::GetIntegerValue(100), nullptr); key4->SetValue(1, ValueFactory::GetIntegerValue(101), nullptr); delete key3; delete key4; delete key_schema; delete table; tuple_id = 0; }
template <class T> bool fastmarch2<T>::fastMarch( std::vector<node2 *> &nodes, FLOAT64 maxdist, FLOAT64 mindist, char type ) { // Check the sign of coefficients if( mindist > 0.0 ) { email::print("mindist must be negative.\n" ); email::send(); exit(0); } if( maxdist < 0.0 ) { email::print("maxdist must be positive.\n" ); email::send(); exit(0); } // Initialize for( uint n=0; n<nodes.size(); n++ ) { node2 *node = nodes[n]; node->new_value = T(); node->new_levelset = 0.0; } // Gather unfixed nodes std::list<node2 *> unfixed; for( uint n=0; n<nodes.size(); n++ ) { node2 *node = nodes[n]; if( node->p2p.empty() ) continue; if( ! node->fixed ) { if( type == 1 ) node->levelset = (node->levelset > 0.0 ? maxdist : mindist); unfixed.push_back(node); } } // Now repeat the propagation... while( true ) { // Gather narrow band nodes std::list<node2 *> narrowList; for( typename std::list<node2 *>::iterator it=unfixed.begin(); it!=unfixed.end(); it++ ) { node2 *node = *it; if( node->p2p.empty() ) continue; if( ! node->fixed ) { // Sort order of connections std::sort(node->p2p.begin(),node->p2p.end(),node2()); // Collect narrow bands node2 *neigh = node->p2p[0]; if( neigh->fixed ) { if( neigh->levelset < maxdist && neigh->levelset > mindist ) { narrowList.push_back(node); } } } } // If not found, just leave the loop if( narrowList.empty() ) break; // Find the minimum edge length and min distance FLOAT64 ds = 1.0; FLOAT64 dist = 1.0; for( typename std::list<node2 *>::iterator it=narrowList.begin(); it!=narrowList.end(); it++ ) { node2 *node = *it; node2 *neigh = node->p2p[0]; if( neigh->fixed ) { ds = fmin(ds,(node->p-neigh->p).len()); dist = fmin(dist,fabs(neigh->levelset)); } } // Cut out the narrow bands to regularize the propagation speed for( typename std::list<node2 *>::iterator it=narrowList.begin(); it!=narrowList.end(); ) { node2 *node = *it; if( node->p2p.empty() ) continue; node2 *neigh = node->p2p[0]; if( fabs(neigh->levelset) > dist+ds ) { it = narrowList.erase(it); } else { it ++; } } // Tranfer to vector container std::vector<node2 *> narrowNodes; narrowNodes.insert(narrowNodes.end(),narrowList.begin(),narrowList.end()); // Propagate once PARALLEL_FOR for( uint n=0; n<narrowNodes.size(); n++ ) { node2 *node = narrowNodes[n]; if( node->p2p.empty() ) continue; // Pick neighboring nodes std::vector<node2 *> tri(node->p2p.size()+1); tri[0] = node; for( uint i=0; i<node->p2p.size(); i++ ) tri[1+i] = node->p2p[i]; // Find the number of valid connections uint numValid=0; if( node->p2p.size() > 2 && tri[1]->fixed && tri[2]->fixed ) numValid = 2; else if( node->p2p.size() > 1 && tri[1]->fixed ) numValid = 1; // Compute shape function if necessary FLOAT64 M[NUM_VERT][NUM_VERT]; if( numValid == 2 ) { FLOAT64 A[NUM_VERT][NUM_VERT]; for( uint i=0; i<numValid+1; i++ ) for( uint j=0; j<numValid+1; j++ ) { if( i < numValid ) A[i][j] = tri[j]->p[i]; else A[i][j] = 1.0; } if( ! invert3x3(A,M)) numValid = 1; } if( type == 0 ) { // Quantity extrapolation // Compute neighbors absolute value FLOAT64 max_len = 0.0; FLOAT64 min_len = 1e18; for( uint m=0; m<node->p2p.size(); m++ ) { if( node->p2p[m]->fixed ) { max_len = fmax(max_len,length(node->p2p[m]->value)); min_len = fmin(min_len,length(node->p2p[m]->value)); } } if( numValid == 2 ) { // Compute gradient of levelset vec2d gradient; for( uint dim=0; dim<numValid; dim++ ) { for( uint k=0; k<numValid+1; k++ ) gradient[dim] += tri[k]->levelset*M[k][dim]; } // Compute determinant FLOAT64 det = 0.0; for( uint dim=0; dim<numValid; dim++ ) { det += gradient[dim]*M[0][dim]; } // Check that gradient is correct FLOAT64 deviation = fabs(gradient.len2()-1.0); if( deviation < 1e-3 ) { // If below the tolerance... // Compute right hand side T rhs = T(); for( uint i=0; i<numValid; i++ ) for( uint j=1; j<numValid+1; j++ ) { rhs += gradient[i]*(-M[j][i])*tri[j]->value; } // Compute the value if( det ) { node->new_value = rhs / det; } else { node->new_value = 0.5*(tri[1]->value+tri[2]->value); printf( "Extrapolation failed. Determination was zero.\n" ); } } else { // Just copy averaged one node->new_value = 0.5*(tri[1]->value+tri[2]->value); } } else if( numValid == 1 ) { // If only one neighbor is fixed, just copy that one node->new_value = tri[1]->value; } else { node->value = T(); } // Normalize if necessary FLOAT64 len = length(node->new_value); if( len > max_len ) node->new_value = normalize(node->new_value, max_len); if( len < min_len ) node->new_value = normalize(node->new_value, min_len); } else if( type == 1 ) { // Levelset extrapolation int sgn = tri[0]->levelset > 0.0 ? 1 : -1; if( numValid == 2 ) { // Build quadric equation vec2d det; vec2d coef; for( uint dim=0; dim<numValid; dim++ ) { det[dim] = M[0][dim]; coef[dim] = 0.0; for( uint k=1; k<numValid+1; k++ ) { coef[dim] += M[k][dim]*tri[k]->levelset; } } // Compute quadric coefficients FLOAT64 A = det.len2(); FLOAT64 B = 2.*det*coef; FLOAT64 C = coef.len2()-1.0; if( A ) { FLOAT64 D = B/A; node->new_levelset = sgn*0.5*sqrtf(fmax(1e-8,D*D-4.0*C/A))-0.5*D; } else { email::print( "determinant was zero !\n" ); email::send(); exit(0); } } else if( numValid == 1 ) { // If only one neighbor is fixed, just copy that one node->new_levelset = tri[1]->levelset+sgn*(tri[1]->p-tri[0]->p).len(); } else { node->new_levelset = 0.0; } } } // Fix the narrow bands PARALLEL_FOR for( uint n=0; n<narrowNodes.size(); n++ ) { node2 *node = narrowNodes[n]; if( node->p2p.empty() ) continue; if( type == 0 ) node->value = node->new_value; else if( type == 1 ) node->levelset = fmax(mindist,fmin(maxdist,node->new_levelset)); node->fixed = true; } } return true; }
void Window_manifold_2::determine_primaries( const COM::DataItem *pconn_n) { // Using the pane connectivity to construct a helper map bm, which // maps from the pane IDs of each pair of incident panes to its // correponding arrays in b2v. // Note in each pane-ID pair, the first ID is no greater than the second. typedef std::map< std::pair<int,int>, std::pair< const int*, const int*> > B2v_map; B2v_map bm; const int pconn_offset=MAP::Pane_connectivity::pconn_offset(); for ( int i=0, n=_pms.size(); i<n; ++i) { // const COM::DataItem *pconn_l = _pms[i].pane()->dataitem(pconn_n->id()); const COM::DataItem *pconn_l = _pms[i]->pane()->dataitem(pconn_n->id()); const int *b2v_l = (const int*)pconn_l->pointer(); int pane_id_l = i; for ( int j=pconn_offset, nj=pconn_l->size_of_real_items(); j<nj; j+=b2v_l[j+1]+2) { std::map<int,int>::iterator it= _pi_map.find( b2v_l[j]); if ( it == _pi_map.end()) continue; // skip remote panes int pane_id_r = it->second; if ( pane_id_l <= pane_id_r) bm[ std::make_pair( pane_id_l, pane_id_r)].first = &b2v_l[j+1]; if ( pane_id_l >= pane_id_r) bm[ std::make_pair( pane_id_r, pane_id_l)].second = &b2v_l[j+1]; } } // Now loop through bm to compute _nd_prm within the process. for ( B2v_map::const_iterator it=bm.begin(); it!=bm.end(); ++it) { // Pane_manifold_2 *p1 = &_pms[it->first.first]; // Pane_manifold_2 *p2 = &_pms[it->first.second]; Pane_manifold_2 *p1 = _pms[it->first.first]; Pane_manifold_2 *p2 = _pms[it->first.second]; const int *v1 = it->second.first, *v2=it->second.second; int is_branchcut = (it->first.first == it->first.second); COM_assertion_msg( ! is_branchcut || *v1%2==0, "Branch-cut must list nodes in pairs."); for ( int k=1, nk=*v1; k<=nk; ++k) { Node node1( p1, v1[k], ACROSS_PANE); Node node2( p2, v2[k+is_branchcut], ACROSS_PANE); int i1 = p1->get_bnode_index( v1[k]); if ( i1>=0 && !node2.is_isolated() && ( node2.halfedge().is_border() || node1.is_isolated() && p1->_nd_prm[i1].pane()==0 )) { p1->_nd_prm[i1] = node2; } else { int i2 = p2->get_bnode_index( v2[k+is_branchcut]); if ( i2 >= 0 && !node1.is_isolated() && (node1.halfedge().is_border() || p2->_nd_prm[i2].pane()==0)) { p2->_nd_prm[i2] = node1; } } if (is_branchcut) ++k; } } }
int main(int argc, char* argv[]) { // Check arguments if (argc < 5) { std::cerr << "Usage: final_project NODES_FILE TRIS_FILE ball.nodes ball.tris \n"; exit(1); } MeshType mesh; std::vector<typename MeshType::node_type> mesh_node; // Read all water Points and add them to the Mesh std::ifstream nodes_file(argv[1]); Point p; uint water_nodes = 0; while (CS207::getline_parsed(nodes_file, p)) { mesh_node.push_back(mesh.add_node(p)); water_nodes++; } // Read all water mesh triangles and add them to the Mesh std::ifstream tris_file(argv[2]); std::array<int,3> t; int water_tris = 0; while (CS207::getline_parsed(tris_file, t)) { mesh.add_triangle(mesh_node[t[0]], mesh_node[t[1]], mesh_node[t[2]]); water_tris++; } uint water_edges = mesh.num_edges(); std::ifstream nodes_file2(argv[3]); double radius = 1 * scale; while (CS207::getline_parsed(nodes_file2, p)) { p *= scale; p.z += + start_height; mesh_node.push_back(mesh.add_node(p)); } // Read all ball mesh triangles and add them to the mesh std::ifstream tris_file2(argv[4]); while (CS207::getline_parsed(tris_file2, t)) { mesh.add_triangle(mesh_node[t[0]+water_nodes], mesh_node[t[1]+water_nodes], mesh_node[t[2]+water_nodes]); } // Print out the stats std::cout << mesh.num_nodes() << " " << mesh.num_edges() << " " << mesh.num_triangles() << std::endl; /* Set the initial conditions */ // Set the initial values of the nodes and get the maximum height double double max_h = 0; double dx = 0; double dy = 0; auto init_cond = Still(); auto b_init_cond = Cone(); // Find the maximum height and apply initial conditions to nodes for (auto it = mesh.node_begin(); it != mesh.node_end(); ++it) { auto n = *it; if (n.index() < water_nodes){ n.value().q = init_cond(n.position()); n.value().b = b_init_cond(n.position()); max_h = std::max(max_h, n.value().q.h); } else { n.value().q = QVar(n.position().z, 0, 0); n.value().mass = total_mass/(mesh.num_nodes() - water_nodes); n.value().velocity = Point(0.0,0.0,0.0); } } // Set the initial values of the triangles to the average of their nodes and finds S // Set the triangle direction values so that we can determine which // way to point normal vectors. This part assumes a convex shape Point center = get_center(mesh); for (auto it = mesh.triangle_begin(); it != mesh.triangle_end(); ++it) { auto t = *it; if (t.index() < water_tris){ t.value().q_bar = (t.node1().value().q + t.node2().value().q + t.node3().value().q) / 3.0; t.value().q_bar2 = t.value().q_bar; double b_avg = (t.node1().value().b + t.node2().value().b + t.node3().value().b) / 3.0; // finds the max dx and dy to calculate Source dx = std::max(dx, fabs(t.node1().position().x - t.node2().position().x)); dx = std::max(dx, fabs(t.node2().position().x - t.node3().position().x)); dx = std::max(dx, fabs(t.node3().position().x - t.node1().position().x)); dy = std::max(dy, fabs(t.node1().position().y - t.node2().position().y)); dy = std::max(dy, fabs(t.node2().position().y - t.node3().position().y)); dy = std::max(dy, fabs(t.node3().position().y - t.node1().position().y)); t.value().S = QVar(0, -grav * t.value().q_bar.h * b_avg / dx, -grav * t.value().q_bar.h * b_avg / dy); } else set_normal_direction((*it),center); } // Calculate the minimum edge length and set edge inital condititons double min_edge_length = std::numeric_limits<double>::max(); uint count = 0; for (auto it = mesh.edge_begin(); it != mesh.edge_end(); ++it, count++){ if (count < water_edges) min_edge_length = std::min(min_edge_length, (*it).length()); else { (*it).value().spring_constant = spring_const; (*it).value().initial_length = (*it).length(); } } // Launch the SDLViewer CS207::SDLViewer viewer; viewer.launch(); auto node_map = viewer.empty_node_map(mesh); viewer.add_nodes(mesh.node_begin(), mesh.node_end(), Color(water_nodes), NodePosition(), node_map); viewer.add_edges(mesh.edge_begin(), mesh.edge_end(), node_map); // adds solid color-slows down program significantly //viewer.add_triangles(mesh.triangle_begin(), mesh.triangle_end(), node_map); viewer.center_view(); // CFL stability condition requires dt <= dx / max|velocity| // For the shallow water equations with u = v = 0 initial conditions // we can compute the minimum edge length and maximum original water height // to set the time-step // Compute the minimum edge length and maximum water height for computing dt double dt = 0.25 * min_edge_length / (sqrt(grav * max_h)); double t_start = 0; double t_end = 10; Point ball_loc = Point(0,0,0); double dh = 0; // double pressure = gas_const/(4/3*M_PI*radius*radius*radius); // add listener my_listener* l = new my_listener(viewer,mesh,dt); viewer.add_listener(l); // Preconstruct a Flux functor EdgeFluxCalculator f; // defines the constraint PlaneConstraint c = PlaneConstraint(plane_const); // Begin the time stepping for (double t = t_start; t < t_end; t += dt) { // define forces on ball GravityForce g_force; BuoyantForce b_force = BuoyantForce(dh, ball_loc.z); WindForce w_force; MassSpringForce ms_force; // PressureForce p_force = PressureForce(pressure); // DampingForce d_force = DampingForce(mesh.num_nodes()); auto combined_forces = make_combined_force(g_force, b_force, w_force, ms_force); // Step forward in time with forward Euler hyperbolic_step(mesh, f, t, dt, ball_loc, water_tris); // Update node values with triangle-averaged values ball_loc = post_process(mesh, combined_forces, c, t, dt, water_nodes); // Update the viewer with new node positions viewer.add_nodes(mesh.node_begin(), mesh.node_end(), Color(water_nodes), NodePosition(), node_map); // viewer.add_triangles(mesh.triangle_begin(), mesh.triangle_end(), node_map); viewer.set_label(t); // find radius of cross sectional radius of ball submerged dh = ball_loc.z; if (dh > 2*radius) dh = 2 * radius; ball_loc.z = cross_radius(radius, dh); // These lines slow down the animation for small meshes. if (mesh.num_nodes() < 100) CS207::sleep(0.05); } return 0; }
int main(void) { int c1 ; int i2 ; { c1 = 0; r1 = __VERIFIER_nondet_char(); id1 = __VERIFIER_nondet_char(); st1 = __VERIFIER_nondet_char(); send1 = __VERIFIER_nondet_char(); mode1 = __VERIFIER_nondet_bool(); alive1 = __VERIFIER_nondet_bool(); id2 = __VERIFIER_nondet_char(); st2 = __VERIFIER_nondet_char(); send2 = __VERIFIER_nondet_char(); mode2 = __VERIFIER_nondet_bool(); alive2 = __VERIFIER_nondet_bool(); id3 = __VERIFIER_nondet_char(); st3 = __VERIFIER_nondet_char(); send3 = __VERIFIER_nondet_char(); mode3 = __VERIFIER_nondet_bool(); alive3 = __VERIFIER_nondet_bool(); id4 = __VERIFIER_nondet_char(); st4 = __VERIFIER_nondet_char(); send4 = __VERIFIER_nondet_char(); mode4 = __VERIFIER_nondet_bool(); alive4 = __VERIFIER_nondet_bool(); i2 = init(); __VERIFIER_assume(i2); p1_old = nomsg; p1_new = nomsg; p2_old = nomsg; p2_new = nomsg; p3_old = nomsg; p3_new = nomsg; p4_old = nomsg; p4_new = nomsg; i2 = 0; while (i2 < 8) { { node1(); node2(); node3(); node4(); p1_old = p1_new; p1_new = nomsg; p2_old = p2_new; p2_new = nomsg; p3_old = p3_new; p3_new = nomsg; p4_old = p4_new; p4_new = nomsg; c1 = check(); assert(c1); i2 ++; } } } return 0; }
void CsrMatrixGpu::createStructure(const Triangle1* const elements, const size_t num_elem) { const size_t max_rowlength(20); size_t* num_nonzeros = new size_t[_numrows]; for (size_t i(0); i < _numrows; ++i) num_nonzeros[i] = 0; size_t* colind = new size_t[max_rowlength*_numrows]; for (size_t i(0); i < num_elem; ++i) { size_t nodes[3]; nodes[0] = elements[i].nodeA; nodes[1] = elements[i].nodeB; nodes[2] = elements[i].nodeC; for (size_t node1(0); node1 < 3; ++node1) { for (size_t node2(0); node2 < 3; ++node2) { size_t a(nodes[node1]); size_t b(nodes[node2]); size_t j(0); while (j < num_nonzeros[a] && colind[a*max_rowlength + j] != b) ++j; if (num_nonzeros[a] == j) { ++(num_nonzeros[a]); assert(num_nonzeros[a] <= max_rowlength); colind[a*max_rowlength + j] = b; } } } } for (size_t i(0); i < _numrows; ++i) for (size_t a(num_nonzeros[i]-1); a > 0; --a) for (size_t b(0); b < a; ++b) if (colind[i*max_rowlength + b] > colind[i*max_rowlength + b+1]) { size_t tmp(colind[i*max_rowlength + b]); colind[i*max_rowlength + b] = colind[i*max_rowlength + b+1]; colind[i*max_rowlength + b+1] = tmp; } size_t* h_rowptr = new size_t[_numrows+1]; size_t num_values(0); for (size_t i(0); i < _numrows; ++i) { h_rowptr[i] = num_values; num_values += num_nonzeros[i]; } h_rowptr[_numrows] = num_values; free_cuda(_colind); malloc_cuda(&_colind, num_values*sizeof(size_t)); size_t* h_colind = new size_t[num_values]; size_t current_pos(0); for (size_t row(0); row < _numrows; ++row) for (size_t col(0); col < num_nonzeros[row]; ++col) h_colind[current_pos++] = colind[row*max_rowlength + col]; free_cuda(_values); malloc_cuda(&_values, num_values*sizeof(float)); float* h_values = new float[num_values]; for (size_t i(0); i < num_values; ++i) h_values[i] = 0.0; memcpy_cuda(_colind, h_colind, num_values*sizeof(size_t), h2d); memcpy_cuda(_rowptr, h_rowptr, (_numrows+1)*sizeof(size_t), h2d); memcpy_cuda(_values, h_values, num_values*sizeof(float), h2d); delete[] num_nonzeros; delete[] colind; delete[] h_rowptr; delete[] h_colind; delete[] h_values; //cudaDeviceSynchronize(); // needed? }
int main (int argv, char **argc) { MaxStack maxStackObj; try { maxStackObj.Pop(); } catch (std::exception &e) { std::cout << e.what() << std::endl; } try { maxStackObj.Max(); } catch (std::exception &e) { std::cout << e.what() << std::endl; } maxStackObj.Push(-78); std::cout << "Max: " << maxStackObj.Max() << std::endl; maxStackObj.Push(-7); std::cout << "Max: " << maxStackObj.Max() << std::endl; maxStackObj.Push(3); std::cout << "Max: " << maxStackObj.Max() << std::endl; maxStackObj.Pop(); std::cout << "Max: " << maxStackObj.Max() << std::endl; maxStackObj.Pop(); std::cout << "Max: " << maxStackObj.Max() << std::endl; maxStackObj.Pop(); maxStackObj.Push(0); std::cout << "Max: " << maxStackObj.Max() << std::endl; maxStackObj.Push(100); std::cout << "Max: " << maxStackObj.Max() << std::endl; Stack stackObj; std::cout << "Result of RPN expr: (3 4 + 2 * 1 +) is :" << stackObj.EvaluateRpn("3 4 + 2 * 1 +") << std::endl; std::cout << "Result of RPN expr: (5 1 2 + 4 * + 3 -) is :" << stackObj.EvaluateRpn("5 1 2 + 4 * + 3 -") << std::endl; std::cout << "Expression : [({[()]})] is :"; stackObj.IsWellFormed("[({[()]})]") ? std::cout << "Well Formed" << std::endl : std::cout << "Not Well Formed" << std::endl; std::cout << "Expression : [{{{}}}[][]]]]({[()]})] is :"; stackObj.IsWellFormed("[{{{}}}[][]]]]({[()]})]") ? std::cout << "Well Formed" << std::endl : std::cout << "Not Well Formed" << std::endl; std::cout << "Expression : ({[()]}){{}}[ is :"; stackObj.IsWellFormed("({[()]}){{}}[") ? std::cout << "Well Formed" << std::endl : std::cout << "Not Well Formed" << std::endl; Node node(23); Node node1(37); Node node2(29); Node node3(41); Node node4(31); node.right = &node1; node1.left = &node2; node1.right = &node3; node2.right = &node4; std::cout << "BST InOrder with stack from 23 is: " << std::endl; std::vector<int> inOrder = stackObj.BSTSortedOrderWithStack(&node); for (auto i : inOrder) { std::cout << i << " "; } std::cout << std::endl; std::cout << "Building with input stream East to West: [4 3 5 3 1 4 2] " << std::endl; std::cout << "Building indices with sunset views are: " << std::endl; std::vector<int> result1 = stackObj.BuildingsWithSunsetViewEastToWest("4 3 5 3 1 4 2"); for (auto i : result1) { std::cout << i+1 << " "; } std::cout << std::endl; std::cout << "Building with input stream West to East: [2 4 1 3 5 3 4] " << std::endl; std::cout << "Building indices with sunset views are: " << std::endl; std::vector<int> result2 = stackObj.BuildingsWithSunsetViewWestToEast("2 4 1 3 5 3 4"); for (auto i : result2) { std::cout << i+1 << " "; } std::cout << std::endl; std::stack<int> s; s.push(5); s.push(4); s.push(3); s.push(2); s.push(1); std::cout << "Stack with LIFO: 1 2 3 4 5" << std::endl; stackObj.SortStack(s); std::cout << "Sorted Stack in descending order" << std::endl; int size = s.size(); for (int i = 0; i < size; i++) { std::cout << s.top() << " "; s.pop(); } std::cout << std::endl; return 0; }