bool IdiotSolver::canMoveAway(int pile ) const { Q_ASSERT( pile < 4 ); if ( Wlen[pile] == 0 ) return false; for ( int i = 0; i < 4; ++i ) Q_ASSERT( Wp[i] = &W[i][Wlen[i] - 1] ); return ( ( Wlen[0] && higher( *Wp[pile], *Wp[0] ) ) || ( Wlen[1] && higher( *Wp[pile], *Wp[1] ) ) || ( Wlen[2] && higher( *Wp[pile], *Wp[2] ) ) || ( Wlen[3] && higher( *Wp[pile], *Wp[3] ) ) ); }
void BFS(struct Graph* g,int j) { int *visit; struct AdjListNode *temp; temp=(struct AdjListNode*)malloc(sizeof(struct AdjListNode)); int n,y,i; n=g->V; visit=(int*)calloc(n,sizeof(int)); enqueue(j); visit[j]=1; while(!isEmpty()) { y=dequeue(); temp=g->array[y].head; while(temp!=NULL) { if(visit[temp->dest]==0) { visit[temp->dest]=1; enqueue(temp->dest); answer[j][temp->dest]=answer[temp->dest][j]=higher(answer[j][y],GAP[y][temp->dest]); } temp=temp->next; } } }
TEST(DecreeUnitTest, testIsDecreeEqualWithHigherDecreeNumberOnLeftHandSide) { paxos::Decree lower(paxos::Replica("an_author"), 1, "", paxos::DecreeType::UserDecree); paxos::Decree higher(paxos::Replica("an_author"), 2, "", paxos::DecreeType::UserDecree); ASSERT_FALSE(paxos::IsDecreeEqual(higher, lower)); }
TEST(DecreeUnitTest, testIsDecreeLowerWithIdenticalDecrees) { paxos::Decree lower(paxos::Replica("an_author_1"), 1, "", paxos::DecreeType::UserDecree); paxos::Decree higher(paxos::Replica("an_author_1"), 1, "", paxos::DecreeType::UserDecree); ASSERT_FALSE(paxos::IsDecreeLower(higher, lower)); }
TEST(DecreeUnitTest, testIsDecreeLowerWithHigherDecreeNumberOnRightHandSide) { paxos::Decree lower(paxos::Replica("an_author"), 1, "", paxos::DecreeType::UserDecree); paxos::Decree higher(paxos::Replica("an_author"), 2, "", paxos::DecreeType::UserDecree); ASSERT_TRUE(paxos::IsDecreeLower(lower, higher)); }
TEST(DecreeUnitTest, testCompareDecreesWithIdenticalDecrees) { paxos::Decree lower(paxos::Replica("an_author_1"), 1, "", paxos::DecreeType::UserDecree); paxos::Decree higher(paxos::Replica("an_author_1"), 1, "", paxos::DecreeType::UserDecree); ASSERT_TRUE(paxos::CompareDecrees(higher, lower) == 0); }
TEST(DecreeUnitTest, testCompareDecreesWithHigherDecreeNumberOnLeftHandSide) { paxos::Decree lower(paxos::Replica("an_author"), 1, "", paxos::DecreeType::UserDecree); paxos::Decree higher(paxos::Replica("an_author"), 2, "", paxos::DecreeType::UserDecree); ASSERT_TRUE(paxos::CompareDecrees(higher, lower) > 0); }
TEST(DecreeUnitTest, testIsDecreeOrderedWithMuchHigherDecreeNumberOnRightHandSide) { paxos::Decree lower(paxos::Replica("an_author"), 1, "", paxos::DecreeType::UserDecree); paxos::Decree higher(paxos::Replica("an_author"), 99, "", paxos::DecreeType::UserDecree); ASSERT_FALSE(paxos::IsDecreeOrdered(lower, higher)); }
TEST(DecreeUnitTest, testIsDecreeLowerWithHigherDecreeRootNumberOnLeftHandSide) { paxos::Decree lower(paxos::Replica("an_author"), 1, "", paxos::DecreeType::UserDecree); paxos::Decree higher(paxos::Replica("an_author"), 1, "", paxos::DecreeType::UserDecree); higher.root_number = 2; ASSERT_FALSE(paxos::IsDecreeLower(higher, lower)); }
TEST(DecreeUnitTest, testIsRootDecreeEqualWithOrderedRootDecrees) { paxos::Decree lower(paxos::Replica("an_author_1"), 1, "", paxos::DecreeType::UserDecree); lower.root_number = 1; paxos::Decree higher(paxos::Replica("an_author_1"), 1, "", paxos::DecreeType::UserDecree); higher.root_number = 2; ASSERT_FALSE(paxos::IsRootDecreeEqual(lower, higher)); }
TEST(DecreeUnitTest, testIsRootDecreeEqualWithIdenticalRootDecrees) { paxos::Decree lower(paxos::Replica("an_author_1"), 1, "", paxos::DecreeType::UserDecree); lower.root_number = 1; paxos::Decree higher(paxos::Replica("an_author_1"), 2, "", paxos::DecreeType::UserDecree); higher.root_number = 1; ASSERT_TRUE(paxos::IsRootDecreeEqual(lower, higher)); }
int choose_card_null(Player *p, Game *g) { int c = 0; //Wenn Vorhand, spiele niedrigste Karte if(g->p[g->vorhand] == p) { for(int i = 0; i < p->hcardcount; i++) { if(get_val(p->hand[c]) < get_val(p->hand[i])) c = i; } return c; } //Wenn Farbe bekannt werden muss, wähle größtmögliche Karte ohne den Stich zu bekommen oder niedrigste Karte c = -1; for(int i = 0; i < p->hcardcount; i++) { if(get_col(p->hand[i]) == get_col(g->card[g->vorhand])) { if(c == -1) c = i; else { switch(higher(g, p->hand[i], p->hand[c])) { case 1: if(higher(g, p->hand[i], g->card[g->vorhand]) != 1 || (p != g->p[(g->vorhand+1)%3] && higher(g, p->hand[i], g->card[(g->vorhand+1)%3]) != 1)) c = i; break; case -1: if(higher(g, p->hand[c], g->card[g->vorhand]) == 1 && (p == g->p[(g->vorhand+1)%3] || higher(g, p->hand[c], g->card[(g->vorhand+1)%3]) == 1)) c = i; break; } } } } if(c >= 0) return c; //Sonst: wähle höchste farbfremde Karte c = 0; for(int i = 1; i < p->hcardcount; i++) { if(get_val(p->hand[i]) < get_val(p->hand[c])) c = i; } return c; }
bool Clustering::optimize_higher_level(bool always_accept, bool (Clustering::*opt)()) { // first, reduce the clusters to [0..m] size_t num_clus = compress_assignments(node_clus); recalc_internal_data(); // Generate higher level Clustering object if (params.verbosity >= 3) params.debug_out << " Optimize higher level: " << endl; SparseMatrix b = higher_level_graph(a, node_clus, num_clus); Clustering higher(b, params, &clus_stats, extra_loss_self); higher_level_partition(higher.node_partition, node_partition, node_clus, num_clus); // check that loss calculation is correct if (abs(loss - higher.loss) > validate_epsilon) { //(params.check_invariants ? error : warning)("Incorrect loss on higher level: %f != %f", loss, higher.loss); printf("Incorrect loss on higher level: %f != %f\n", loss, higher.loss); if (params.check_invariants) throw std::logic_error("Incorrect loss on higher level"); } // trace for higher level vector<shared_ptr<TraceStep> > sub_trace; vector<node_t> sub_mapping; if (trace_out) { sub_mapping = node_clus; higher.trace_out = &sub_trace; higher.trace("init"); } // now cluster on a higher level bool changes = (higher.*opt)(); //higher.recalc_internal_data(); // make sure loss is exact // use for this? if (changes && (always_accept || higher.loss < this->loss - epsilon)) { merge_from_higher_level(node_clus,higher.node_clus); recalc_internal_data(); if (params.verbosity >= 3) params.debug_out << " Merge from higher level: " << setprecision(12) << higher.loss << " = " << setprecision(12) << this->loss << ", an improvement of " << setprecision(12) << (higher.loss - this->loss) << endl; trace("higher",&sub_trace,&sub_mapping); return true; } else { if (params.verbosity >= 3) params.debug_out << " Don't merge from higher level: " << setprecision(12) << higher.loss << " > " << setprecision(12) << this->loss << endl; return false; } }