/** * Creates a new graph with stronger hypotheses @a h than the parent graph @a f. * \li Marks all the parent nodes in #known_reals as known in this new graph too. * \li Tries to add ::HYPOTHESIS nodes corresponding to bounded interval hypotheses of @a h. * \li Adds other hypotheses of @a h in #partial_reals. */ graph_t::graph_t(graph_t *f, property_vect const &h) : father(f), hyp(h), contradiction(NULL) { graph_loader loader(this); if (f) { assert(hyp.implies(f->hyp)); assert(!f->contradiction); known_reals = f->known_reals; for (node_map::iterator i = known_reals.begin(), end = known_reals.end(); i != end; ++i) ++i->second->nb_good; } for (property_vect::const_iterator i = hyp.begin(), end = hyp.end(); i != end; ++i) { if (i->real.pred_bnd() && !is_bounded(i->bnd())) { if (known_reals.count(i->real) == 0) partial_reals.insert(std::make_pair(i->real, new hypothesis_node(*i))); } else { node *n = new hypothesis_node(*i); try_real(n); } } }
std::vector<int> placement_problem::evaluate_branches_strong(std::vector<generic_constraint> constraints) const{ std::vector<int> ret; for(generic_constraint constraint : constraints){ if(constraint.direction){ auto tmp_flow = y_flow; tmp_flow.add_edge(constraint.sc+1, constraint.fc+1, -constraint.min_dist); if(tmp_flow.is_bounded()) ret.push_back(x_flow.get_cost() + tmp_flow.get_cost()); } else{ auto tmp_flow = x_flow; tmp_flow.add_edge(constraint.sc+1, constraint.fc+1, -constraint.min_dist); if(tmp_flow.is_bounded()) ret.push_back(y_flow.get_cost() + tmp_flow.get_cost()); } } return ret; }
/** * Returns a fully simplified mix of @a opt with @a cur. * Ensures the bounds do not cross the points -1, 0, and -1. * @pre @a cur is a bounded subset of @a opt. * @see ::simplify_full */ static property boundify_full(property const &opt, property const &cur) { property res = opt; interval const &bopt = opt.bnd(), &bcur = cur.bnd(); if (is_bounded(bopt)) return res; res.bnd() = (lower(bopt) == number::neg_inf) ? interval(simplify_full(lower(bcur), -1), upper(bopt)) : interval(lower(bopt), simplify_full(upper(bcur), 1)); return res; }
int main() { double z = 1.0; cout << "Some inquiries into the nature of double:" << endl << "digits(z) = " << digits(z) << endl << "epsilon(z) = " << epsilon(z) << endl << "huge(z) = " << huge(z) << endl << "tiny(z) = " << tiny(z) << endl << "max_exponent(z) = " << max_exponent(z) << endl << "min_exponent(z) = " << min_exponent(z) << endl << "max_exponent10(z) = " << max_exponent10(z) << endl << "min_exponent10(z) = " << min_exponent10(z) << endl << "precision(z) = " << precision(z) << endl << "radix(z) = " << radix(z) << endl; Range r = range(z); cout << "range(z) = [ " << r.first() << ", " << r.last() << " ]" << endl; cout << endl << "More obscure properties:" << endl << "is_signed(z) = " << is_signed(z) << endl << "is_integer(z) = " << is_integer(z) << endl << "is_exact(z) = " << is_exact(z) << endl << "round_error(z) = " << round_error(z) << endl << "has_infinity(z) = " << has_infinity(z) << endl << "has_quiet_NaN(z) = " << has_quiet_NaN(z) << endl << "has_signaling_NaN(z) = " << has_signaling_NaN(z) << endl << "has_denorm(z) = " << has_denorm(z) << endl << "has_denorm_loss(z) = " << has_denorm_loss(z) << endl << "infinity(z) = " << infinity(z) << endl << "quiet_NaN(z) = " << quiet_NaN(z) << endl << "signaling_NaN(z) = " << signaling_NaN(z) << endl << "denorm_min(z) = " << denorm_min(z) << endl << "is_iec559(z) = " << is_iec559(z) << endl << "is_bounded(z) = " << is_bounded(z) << endl << "is_modulo(z) = " << is_modulo(z) << endl << "traps(z) = " << traps(z) << endl << "tinyness_before(z) = " << tinyness_before(z) << endl; return 0; }
static void massage_property_tree(property_tree &tree, context &ctx) { std::vector<property_tree::leave> new_leaves; // for any goal x>=b or x<=b, add the converse inequality as a hypothesis for (std::vector<property_tree::leave>::const_iterator i = tree->leaves.begin(), i_end = tree->leaves.end(); i != i_end; ++i) { property const &p = i->first; if (!i->second || p.real.pred() != PRED_BND || !is_defined(p.bnd()) || is_bounded(p.bnd())) continue; number l = upper(p.bnd()), u = lower(p.bnd()); if (l == number::pos_inf) { l = number::neg_inf; if (!p.real.real2()) { real_op const *o = boost::get<real_op const>(p.real.real()); if (o && o->type == UOP_ABS) l = 0; } } else { u = number::pos_inf; } new_leaves.push_back(property_tree::leave(property(p.real, interval(l, u)), false)); } tree->leaves.insert(tree->leaves.end(), new_leaves.begin(), new_leaves.end()); new_leaves.clear(); typedef std::map< predicated_real, property > input_set; input_set inputs; // intersect hypothesis properties for common reals for (std::vector<property_tree::leave>::const_iterator i = tree->leaves.begin(), i_end = tree->leaves.end(); i != i_end; ++i) { if (i->second) { new_leaves.push_back(*i); continue; } property const &p = i->first; std::pair< input_set::iterator, bool > ib = inputs.insert(std::make_pair(p.real, p)); if (!ib.second) // there was already a known range ib.first->second.intersect(p); } for (input_set::const_iterator i = inputs.begin(), i_end = inputs.end(); i != i_end; ++i) { ctx.hyp.push_back(i->second); if (!i->second.real.pred_bnd()) continue; interval const &bnd = i->second.bnd(); // bail out early if there is an empty set on an input if (is_empty(bnd)) { std::cerr << "Warning: the hypotheses on " << dump_real_short(i->first) << " are trivially contradictory, skipping.\n"; exit(0); } } tree->leaves = new_leaves; if (!tree->subtrees.empty() || !tree->leaves.empty()) ctx.goals = tree; }
int main() { freopen("maze.txt", "r", stdin); freopen("result.txt", "w", stdout); // get input from file read_maze(); // print out the maze const char conversion_to_maze[3] = {'X', '.', 'o'}; for (int i = 0; i < 2; i++) { for (int j = 0; j < MAZE_ROW; j++) { for (int k = 0; k < MAZE_COL; k++) { printf("%c", conversion_to_maze[maze[i][j][k]]); } printf("\n"); } } // initialize the stacks and map State ratA = {0, 1, 1, 0}; State ratB = {1, 99, 99, 0}; posA = posB = 0; stackA[posA++] = ratA; stackB[posB++] = ratB; bool visitedA[2][MAZE_ROW][MAZE_COL], visitedB[2][MAZE_ROW][MAZE_COL]; memset(visitedA, 0, sizeof(visitedA)); memset(visitedB, 0, sizeof(visitedB)); // if one of them reached the dest. or they meet, terminate bool need_continue = true; while (need_continue) { bool reach_A_dest = false, reach_B_dest = false; State curr; // walk mouse A // printf("Walk Mouse A\n"); while (posA != 0) { curr = stackA[posA - 1]; visitedA[curr.f][curr.x][curr.y] = true; // printf("curr -> %d %d %d %d\n", curr.f, curr.x, curr.y, curr.next_dir); bool has_next_step = false; for (int i = curr.next_dir; i < 4; i++) { // printf("Trying %d dirA\n", i); State tmp = curr; tmp.x = curr.x + dirA[i][0]; tmp.y = curr.y + dirA[i][1]; tmp.next_dir = 0; // printf("tmp -> %d %d %d %d\n", tmp.f, tmp.x, tmp.y, tmp.next_dir); if (is_bounded(tmp) && maze[tmp.f][tmp.x][tmp.y] != WALL && visitedA[tmp.f][tmp.x][tmp.y] == false) { // printf("posA %d\n", posA); if (maze[tmp.f][tmp.x][tmp.y] == STAIR && tmp.f == 0) { // RatA can only go up once! tmp.f = 1; } else { stackA[posA - 1].next_dir = i + 1; } stackA[posA++] = tmp; has_next_step = true; break; } } if (is_A_dest(stackA[posA - 1])) { reach_A_dest = true; need_continue = false; break; } if (has_next_step == false) { posA--; break; } else { break; } } // walk mouse B (walk one mouse first) // printf("Walk Mouse B\n"); while (posB != 0) { curr = stackB[posB - 1]; visitedB[curr.f][curr.x][curr.y] = true; // printf("curr -> %d %d %d %d\n", curr.f, curr.x, curr.y, curr.next_dir); bool has_next_step = false; for (int i = curr.next_dir; i < 4; i++) { // printf("Trying %d dirB\n", i); State tmp = curr; tmp.x = curr.x + dirB[i][0]; tmp.y = curr.y + dirB[i][1]; tmp.next_dir = 0; // printf("tmp -> %d %d %d %d\n", tmp.f, tmp.x, tmp.y, tmp.next_dir); if (is_bounded(tmp) && maze[tmp.f][tmp.x][tmp.y] != WALL && visitedB[tmp.f][tmp.x][tmp.y] == false) { // printf("posB %d\n", posB); if (maze[tmp.f][tmp.x][tmp.y] == STAIR && tmp.f == 1) { // RatB can only go down once! tmp.f = 0; } else { stackB[posB - 1].next_dir = i + 1; } stackB[posB++] = tmp; has_next_step = true; break; } } if (is_B_dest(stackB[posB - 1])) { reach_B_dest = true; need_continue = false; break; } if (has_next_step == false) { posB--; break; } else { break; } } if (reach_A_dest || reach_B_dest) { // rat(s) reached dest. // According to the ans., when the rat reaches the dest., that coor. // doesn't need to be printed out! if (reach_A_dest && reach_B_dest) { // reach dest. at the same time, no coor. to be printed printf("rats didn't encounter each other in this maze\n"); } else if (reach_A_dest) { // A reaches the dest. only (ans1), print msg. and terminate the program // now! printf("rats didn't encounter each other in this maze\n"); } else { // B reaches the dest. only, so print A's coor and the msg., then // terminate the program printf("ratA(%d,%d,%d)\n", stackA[posA - 1].f, stackA[posA - 1].x, stackA[posA - 1].y); printf("rats didn't encounter each other in this maze\n"); } } else if (is_same_location(stackA[posA - 1], stackB[posB - 1])) { #if DEBUG <= 2 printf("meet!\n"); printf("ratA(%d,%d,%d)\n", stackA[posA - 1].f, stackA[posA - 1].x, stackA[posA - 1].y); printf("ratB(%d,%d,%d)\n", stackB[posB - 1].f, stackB[posB - 1].x, stackB[posB - 1].y); #endif // print out A's coor and then print the msg, then terminate the program printf("ratA(%d,%d,%d)\n", stackA[posA - 1].f, stackA[posA - 1].x, stackA[posA - 1].y); // Bug fixed, thanks to Bemg printf("rats encounter each other in (%d,%d,%d)\n", stackB[posB - 1].f, stackB[posB - 1].x, stackB[posB - 1].y); need_continue = false; } else { printf("ratA(%d,%d,%d)\n", stackA[posA - 1].f, stackA[posA - 1].x, stackA[posA - 1].y); printf("ratB(%d,%d,%d)\n", stackB[posB - 1].f, stackB[posB - 1].x, stackB[posB - 1].y); } } return 0; }