ActionConditions Planner::findActions(Actions actions, Conditions preConditions){ ActionConditions result; for(auto& a: actions){ Conditions postA = a->getPreConditions(); if(satisfies(postA, preConditions)){ Conditions yetToSatisfy; std::set_difference(preConditions.begin(),preConditions.end(), postA.begin(), postA.end(), std::inserter(yetToSatisfy, yetToSatisfy.begin()) ); Conditions combined; Conditions preA = a->getPostConditions(); std::set_union(preA.begin(), preA.end(), yetToSatisfy.begin(), yetToSatisfy.end(), std::inserter(combined, combined.begin())); bool c = false; for(auto& m : mutexes) if(satisfies(combined, m)){ c=true;break; } if(!c) result.insert({combined,a}); } } return result; }
void ecs::BaseSystem::entityModified(ecs::EntityID entityID) { auto find = findEntity(entityID); if(satisfies(entityID) && find == entities_.end()) { entities_.push_back(managerRef_->createHandle(entityID)); } else if(!satisfies(entityID) && find != entities_.end()) { entities_.erase(find); } }
void write_graphviz( std::string const& filename, std::vector<int> const& model, Karrot::Database const& database) { std::ofstream dot_file(filename); dot_file << "digraph G {\n"; for (std::size_t i = 0; i < model.size(); ++i) { auto& entry = database[model[i]]; dot_file << " " << i << " [" << "label=\"" << entry.name << ' ' << entry.version << "\", " << "URL=\"" << entry.id << "\"" << "];" << std::endl; ; for (std::size_t k = 0; k < model.size(); ++k) { for (auto& spec : database[model[k]].depends) { if (satisfies(entry, spec)) { dot_file << " " << k << " -> " << i << ";\n"; } } } } dot_file << "}\n"; }
std::vector<int> topological_sort(std::vector<int> const& model, Database const& database) { std::vector<int> topo_order; std::size_t size = model.size(); std::vector<std::vector<int>> graph(size); for (std::size_t i = 0; i < size; i++) { auto& impl = database[model[i]]; for (std::size_t k = 0; k < size; k++) { for (auto& dep : database[model[k]].depends) { if (satisfies(impl, dep)) { graph[i].push_back(k); } } } } auto insert = [&topo_order, &model](int idx) { topo_order.push_back(model[idx]); }; boost::topological_sort(graph, boost::make_function_output_iterator(insert), boost::vertex_index_map(boost::identity_property_map())); std::reverse(std::begin(topo_order), std::end(topo_order)); return topo_order; }
int main() { int a = 0, b = 0, c = 0; int result; result = satisfies(a, b, c); printf("%i", result); return 0; }
ActionPlan Planner::Plan2(){ ActionPlan result; auto curr = preConds; auto goal = postConds; ActionPtr nullAction = Action::ActionFactory("NULL",{},{},0,0); ActionCondition start = {curr, nullAction}; PriorityQueue<ActionNodePtr> acs; auto curr_ac = std::make_shared<ActionNode>(); curr_ac->action = nullAction; curr_ac->conds = curr; curr_ac->cost_so_far = 0; curr_ac->parent = nullptr; acs.put(curr_ac,0); bool success = false; while(!acs.empty()){ curr_ac = acs.get(); if(!satisfies(curr_ac->conds, goal)){ for(auto& ac : findActions(actions, curr_ac->conds)){ bool skip = false; auto temp_ac = curr_ac; while(temp_ac->action->getName() != nullAction->getName()){ temp_ac = temp_ac->parent; if(ac.first == temp_ac->conds){ skip=true; break; } } if(skip) continue; auto node = std::make_shared<ActionNode>(); node->action = ac.second; node->conds = ac.first; node->cost_so_far = ac.second->getCost()+curr_ac->cost_so_far; node->parent = curr_ac; acs.put(node,node->cost_so_far); } } else{ success=true; break; } } std::cout <<"PLANNED " << std::boolalpha << success << "\n"; if(!success) return result; while(curr_ac != nullptr){ result.push_back(curr_ac->action); //std::cout << curr_ac->action << " "; curr_ac = curr_ac->parent; } std::reverse(result.begin(), result.end()); return result; }
int main() { int aval = -127, bval = -128, cval = -10; int resultVal; resultVal = satisfies(aval, bval, cval); printf("%i", resultVal); return 0; }
int main() { while(!feof(stdin)) { // o1 and o2 are the co-ordinates of the centre, len is the side length float o1, o2, len; // X1 -> x co-ordinate of point X // X2 -> y co-ordinate of point y // a, b, c, d and p are the 5 mentioned points float a1, a2, b1, b2, c1, c2, d1, d2, p1, p2; // The lines perpendicular to ap, bp, cp, dp passing through B, C, D, A line l1, l2, l3, l4; // Point of intersection of lines l1 and l2 point p; point offset; // Get the input if ( scanf("%f%f",&o1,&o2) != 2) break; scanf("%f",&len); scanf("%f%f",&p1,&p2); // set the co-ordinates of points a, b, c and d a1 = o1 + len /2; a2 = o2 + len /2; b1 = o1 + len /2; b2 = o2 - len /2; c1 = o1 - len /2; c2 = o2 - len /2; d1 = o1 - len /2; d2 = o2 + len /2; offset.x = c1; offset.y = c2; a1 -= c1; b1 -= c1; d1 -= c1; p1 -= c1; c1 -= c1; a2 -= c2; b2 -= c2; d2 -= c2; p2 -= c2; c2 -= c2; // Obtain the 4 lines l1.x = a1; l1.y = a2; l1.ma = p1 - b1; l1.mb = b2 - p2; l2.x = b1; l2.y = b2; l2.ma = p1 - c1; l2.mb = c2 - p2; l3.x = c1; l3.y = c2; l3.ma = p1 - d1; l3.mb = d2 - p2; l4.x = d1; l4.y = d2; l4.ma = p1 - a1; l4.mb = a2 - p2; /* Tested, working printf("y - %.1f = %.1f // %.1f x - %.1f\n", l1.y, l1.ma, l1.mb, l1.x); printf("y - %.1f = %.1f // %.1f x - %.1f\n", l2.y, l2.ma, l2.mb, l2.x); printf("y - %.1f = %.1f // %.1f x - %.1f\n", l3.y, l3.ma, l3.mb, l3.x); printf("y - %.1f = %.1f // %.1f x - %.1f\n", l4.y, l4.ma, l4.mb, l4.x); */ // obtain the point of intersection of lines 1 and 2 p = solve (l3, l4); /* Tested printf("%.1f %.1f", p.x, p.y); */ // See if the above point also satisfies lines 3 and 4 if (satisfies(l1, p) && satisfies(l2, p) ) { printf("YES\n%.1f %.1f\n", p.x + offset.x, p.y + offset.y); } else { printf("NO\n"); } getchar(); } return 0; }
void execute(parsed_query& query) { std::vector<int> indices; db::table tb = get_table(query.tables[0]); for(auto& field : query.fields) { if(tb.is_field_present(field)) { indices.push_back(tb.get_index_of_field(field)); } } std::vector<db::row> rows; std::vector<int> tuple; for(int i = 0; i < tb.size(); i++) { db::row rb = tb[i]; for(auto& index : indices) { tuple.push_back(rb[index]); } db::row tmp = db::row(tuple); if(query.conditionals.size() == 0 and query.string_conditionals.size() == 0) { rows.push_back(tmp); } else if(satisfies(tb,rb,query.conditionals,query.string_conditionals,query.logic_op)) { rows.push_back(tmp); } tuple.clear(); } if(!query.dis_column.empty()) { int index = get_index_of_field(query.fields, query.dis_column); auto lt = [index](const db::row& a, const db::row& b){ return a[index] < b[index]; }; auto eq = [index](const db::row& a, const db::row& b){ return a[index] == b[index]; }; std::sort(rows.begin(), rows.end(), lt); auto last = std::unique(rows.begin(), rows.end(), eq); rows.erase(last, rows.end()); } if(query.agg_type != db::aggregate_type::NONE) { int index = get_index_of_field(query.fields, query.agg_column); int summation = 0; auto lt = [index](const db::row& a, const db::row& b){ return a[index] < b[index]; }; auto gt = [index](const db::row& a, const db::row& b){ return a[index] > b[index]; }; std::vector<int> n_tuple; if(query.agg_type == db::aggregate_type::MIN) { std::sort(rows.begin(), rows.end(), lt); rows.erase(rows.begin() + 1, rows.end()); } else if(query.agg_type == db::aggregate_type::MAX) { std::sort(rows.begin(), rows.end(), gt); rows.erase(rows.begin() + 1, rows.end()); } if(query.agg_type == db::aggregate_type::SUM or query.agg_type == db::aggregate_type::AVG) { std::sort(rows.begin(), rows.end(), lt); for(auto& r : rows) { summation += r[index]; } for(int i = 0; i < rows[0].size(); i++) { n_tuple.push_back(rows[0][i]); } if(query.agg_type == db::aggregate_type::AVG) { summation = (int)((double)summation/(double)rows.size()); } n_tuple[index] = summation; rows.clear(); rows.push_back(n_tuple); } } std::cout << to_str(query.fields, false) << std::endl; for(auto& row : rows) { std::cout << row.to_string() << std::endl; } }
void execute_join(parsed_query& query) { db::table tb1 = get_table(query.tables[0]); db::table tb2 = get_table(query.tables[1]); std::vector<int> fields; std::vector<int> table_id; std::vector<int> indices; for(int i = 0; i < query.tables.size(); i++) { db::table tb = get_table(query.tables[i]); for(auto& field : query.fields) { if(tb.is_field_present(field)) { table_id.push_back(i); indices.push_back(tb.get_index_of_field(field)); } } } std::vector<db::row> rows; std::vector<int> tuple; for(int i = 0; i < tb1.size(); i++) { db::row rb1 = tb1[i]; for(int j = 0; j < tb2.size(); j++) { db::row rb2 = tb2[j]; for(int k = 0; k < indices.size(); k++) { if(table_id[k] == 0) tuple.push_back(rb1[indices[k]]); else tuple.push_back(rb2[indices[k]]); } db::row tmp = db::row(tuple); if(query.conditionals.size() == 0 and query.string_conditionals.size() == 0) { rows.push_back(tmp); } else { std::vector<bool> truth_values; bool rv; for(auto& condition : query.conditionals) { auto tmp_table_name = std::get<0>(condition); tmp_table_name = tmp_table_name.substr(0, tmp_table_name.find(".")); std::vector<std::tuple<std::string,std::string,int>> tmp_cond; std::vector<std::tuple<std::string,std::string,std::string>> empty_cond; tmp_cond.push_back(condition); if(tmp_table_name == tb1.name()) { rv = satisfies(tb1,rb1,tmp_cond,empty_cond,query.logic_op); truth_values.push_back(rv); } else if(tmp_table_name == tb2.name()) { rv = satisfies(tb1,rb1,tmp_cond,empty_cond,query.logic_op); truth_values.push_back(rv); } tmp_cond.clear(); } for(auto& str_cond : query.string_conditionals) { rv = satisfies_join(tb1, tb2, rb1, rb2, str_cond); truth_values.push_back(rv); } if(truth_values.size() > 1) { if(query.logic_op == db::logic_type::AND) { if(truth_values[0] and truth_values[1]) { rows.push_back(tmp); } } else if(query.logic_op == db::logic_type::OR) { if(truth_values[0] or truth_values[1]) { rows.push_back(tmp); } } } else if(truth_values[0]) { rows.push_back(tmp); } } tuple.clear(); } } std::cout << to_str(query.fields, false) << std::endl; for(auto& row : rows) { std::cout << row.to_string() << std::endl; } }
int main(void) { int i; char x; struct dec dec; char * tok; char key[4]; if (0) { for (i=0; i<cipher_length; ++i) { printf("%c", lowercase(cipher[i])); } printf("\n"); dec_init(&dec, cipher, cipher_length, "aaa", 3); while (0 != (x = dec_read(&dec))) { printf("%c", lowercase(x)); } printf("\n"); /* tokenizer. */ dec_init(&dec, cipher, cipher_length, "aab", 3); while (NULL != (tok = dec_token(&dec))) { printf("%s -> sig: %llu\n", tok, sign_word(tok)); } return 0; } /* key generator */ double max_score, curr_score; char max_key[4]; init_dict("/usr/share/dict/words"); key[3] = (char)0; for (key[0]='a'; key[0] <= 'z'; ++key[0]) for (key[1]='a'; key[1] <= 'z'; ++key[1]) for (key[2]='a'; key[2] <= 'z'; ++key[2]) { if (1) { curr_score = score(key); if (verbose) printf("key: %s score: %.6lf\n", key, curr_score); if (curr_score > max_score) { max_score = curr_score; memcpy(max_key, key, 4); if (verbose) { printf("\n\n----- new max -- key: %s ---- score: %lf ----\n", max_key, max_score); dec_init(&dec, cipher, cipher_length, max_key, 3); while (0 != (x = dec_read(&dec))) { printf("%c", lowercase(x)); } printf("\n\n\n"); usleep(250000); } } } if (0) { if (satisfies(key)) { printf("good_key: %s\n", key); fprintf(stderr, "good_key: %s\n", key); } else { printf("bad_key: %s\n", key); } } } printf("\n\n------- key: %s ---- score: %lf ----\n", max_key, max_score); int sum = 0; dec_init(&dec, cipher, cipher_length, max_key, 3); while (0 != (x = dec_read(&dec))) { sum += x; printf("%c", x); } printf("\n\n\n"); printf("sum: %d\n", sum); return 0; }
int do_selecting(std:: istream *pInput, std:: ostream *pOutput, int selectColIndex) { std:: vector<long double> colValues; colValues.resize(columnNames.size()); unsigned long long lineNumber = 1; while (! (*pInput).eof()) { std:: string str; std:: getline((*pInput), str, '\n'); if (str.length() == 0 && (*pInput).eof()) { break; // while } if (str.length() >= 1 && str[str.length() - 1] == '\r') { str.resize(str.length() - 1); } ++lineNumber; std:: vector<std:: string> cols; split(&cols, str, "\t"); if (cols.size() != columnNames.size()) { std:: cerr << "error: line #" << lineNumber << ": number of colums differs" << std:: endl; return 1; } bool headdingLine = false; for (size_t i = 0; i < cols.size(); ++i) { if (! str_to_ld(&colValues[i], cols[i])) { headdingLine = true; break; // for i } } if (! headdingLine) { bool satisfiesConditions = true; for (size_t i = 0; i < colValues.size(); ++i) { long double value = colValues[i]; const std:: vector<std:: pair<Condition, int> > &conds = conditionsForColumn[i]; for (size_t j = 0; j < conds.size(); ++j) { const Condition &cond = conds[j].first; if (! satisfies(value, cond)) { satisfiesConditions = false; break; // for j } } if (! satisfiesConditions) { break; // for i } } if (satisfiesConditions) { if (binaryOutputFactor != 0) { long long value = (long long)(colValues[selectColIndex] * binaryOutputFactor); (*pOutput).write((const char *)(void *)&value, sizeof(long long)); } else { (*pOutput) << cols[selectColIndex] << std:: endl; } } } } return 0; }
void ecs::BaseSystem::entityAdded(ecs::EntityID entityID) { if(satisfies(entityID)) { entities_.push_back(managerRef_->createHandle(entityID)); } }
void ecs::BaseSystem::entityRemoved(ecs::EntityID entityID) { if(satisfies(entityID)) { entities_.erase(findEntity(entityID)); } }
Answer CubeLIAModule<Settings>::checkCore() { #ifdef DEBUG_CUBELIAMODULE print(); #endif Answer ans; if( !rReceivedFormula().isRealConstraintConjunction() ) { #ifdef DEBUG_CUBELIAMODULE std::cout << "Call internal LRAModule:" << std::endl; mLRA.print(); #endif mLRA.clearLemmas(); mLRAFormula->updateProperties(); ans = mLRA.check( false, mFullCheck, mMinimizingCheck ); switch( ans ) { case SAT: { clearModel(); // Get the model of mLRA mLRA.updateModel(); const Model& relaxedModel = mLRA.model(); auto iter = mRealToIntVarMap.begin(); for( auto& ass : relaxedModel ) { assert( iter != mRealToIntVarMap.end() ); // Round the result to the next integer mModel.emplace_hint( mModel.end(), iter->second, carl::round( ass.second.asRational() ) ); ++iter; } // Check if the rounded model satisfies the received formula bool receivedFormulaSatisfied = true; for( const FormulaWithOrigins& fwo : rReceivedFormula() ) { unsigned res = satisfies( mModel, fwo.formula() ); switch( res ) { case 0: case 2: receivedFormulaSatisfied = false; default: break; } if( !receivedFormulaSatisfied ) break; } // If we found a model, we know that the formula is satisfiable, otherwise, we have to call the backends on the received formula if( receivedFormulaSatisfied ) { mModelUpdated = true; return SAT; } clearModel(); break; } case UNSAT: { if( Settings::exclude_unsatisfiable_cube_space ) { // Exclude the space for which mLRA has detected unsatisfiability for( auto& infsubset : mLRA.infeasibleSubsets() ) { FormulasT formulas; for( auto& formula : infsubset ) formulas.push_back( formula.negated() ); addLemma( FormulaT( carl::FormulaType::OR, formulas ) ); } } break; } default: assert( false ); } } #ifdef DEBUG_CUBELIAMODULE std::cout << "Call Backends:" << std::endl; #endif // Run backends on received formula ans = runBackends(); if( ans == UNSAT ) getInfeasibleSubsets(); else if( ans == SAT ) mModelUpdated = false; return ans; }