void optargs(int argc, char **argv) { int opt; while ((opt = getopt(argc, argv, "sfdB:")) != -1) { switch (opt) { case 'B': // buffer size bufSize = atoi(optarg); break; case 's': bSync = 1; break; case 'f': bFsync = 1; break; case 'd': bFdatasync = 1; break; default: /* ? */ usage(); } } if (bufSize == 0 || bufSize > MAX_BUF_LEN) bufSize = MAX_BUF_LEN; if (optind < argc) infile = argv[optind++]; if (optind < argc) { outfile = argv[optind]; wrdisk = 1; } printf("O_SYNC:%s, fsync:%s, fdatasync:%s, buffer_size:%d, input:%s, output:%s.\n", truth(bSync), truth(bFsync), truth(bFdatasync), bufSize, infile ? infile : "stdin", outfile); }
truth commandsystem::Go(character* Char) { int Dir = game::DirectionQuestion(CONST_S("In what direction do you want to go? [press a direction key]"), false); if(Dir == DIR_ERROR) return false; go* Go = go::Spawn(Char); Go->SetDirection(Dir); int OKDirectionsCounter = 0; for(int d = 0; d < Char->GetNeighbourSquares(); ++d) { lsquare* Square = Char->GetNeighbourLSquare(d); if(Square && Char->CanMoveOn(Square)) ++OKDirectionsCounter; } Go->SetIsWalkingInOpen(OKDirectionsCounter > 2); Char->SetAction(Go); Char->EditAP(Char->GetStateAPGain(100)); // gum solution Char->GoOn(Go, true); return truth(Char->GetAction()); }
int main (int argc, char const *argv []) { for (argc = 1; argv [argc]; ++argc) { printf (" argv[%2d] = [%s] %d \n", argc, argv [argc], truth (argv [argc], -1)); } printf ("\n"); return (0); }
std::vector<int> solve() { auto flips = 0; auto start = std::clock(); auto state = initializer_(clauses_, variable_count_); while(!sls::util::is_interrupted() && state.unsat().size() > 0) { state.before_pick(flips); selector_->is_applicable(state); auto pick = selector_->select(state); ++flips; state.after_pick(flips, pick); transitor_(state, pick); state.flush(); } auto end = std::clock(); auto time = static_cast<double>(end - start) / static_cast<double>(CLOCKS_PER_SEC); std::cout << "c " << variable_count_ << "," << clauses_.size() << "," << flips << "," << (!sls::util::is_interrupted() ? time : -1.0) << "," << static_cast<int>(static_cast<double>(flips)/time) << std::endl; std::vector<int> model(variable_count_); for(auto i = 0; i < variable_count_; ++i) model[i] = (i + 1) * (static_cast<int>(state.truth(sat_type::make_variable(i + 1))) * 2 - 1); return model; }
int main(int argc, char *argv[]){ //std::string scenarioname = "yosemite"; std::string scenarioname = "whale"; std::unordered_map<std::string, parameter> parameters; makeParameters(parameters); // load images cv::Mat image1 = cv::imread("images/RubberWhale/frame10.png", CV_LOAD_IMAGE_GRAYSCALE); cv::Mat image2 = cv::imread("images/RubberWhale/frame11.png", CV_LOAD_IMAGE_GRAYSCALE); cv::Mat i1; cv::Mat i2; image1.convertTo(i1, CV_64F); image2.convertTo(i2, CV_64F); // load truth GroundTruth truth("images/RubberWhale/flow10.flo"); // create scenario file cv::FileStorage s(scenarioname+".xml", cv::FileStorage::WRITE); s << "scenarioname" << scenarioname; s << "image1" << i1; s << "image2" << i2; s << "groundtruth" << truth.truthfield; s << "truthmask" << truth.mask; s << "interactive" << true; saveParameters(s, parameters); s.release(); }
bool two_sat(int n, const vii& clauses, vi& all_truthy) { all_truthy.clear(); vvi adj(2*n+1); for (int i = 0; i < size(clauses); i++) { adj[-clauses[i].first + n].push_back(clauses[i].second + n); if (clauses[i].first != clauses[i].second) adj[-clauses[i].second + n].push_back(clauses[i].first + n); } pair<union_find, vi> res = scc(adj); union_find scc = res.first; vi dag = res.second; vi truth(2*n+1, -1); for (int i = 2*n; i >= 0; i--) { int cur = order[i] - n, p = scc.find(cur + n), o = scc.find(-cur + n); if (cur == 0) continue; if (p == o) return false; if (truth[p] == -1) truth[p] = 1; truth[cur + n] = truth[p]; truth[o] = 1 - truth[p]; if (truth[p] == 1) all_truthy.push_back(cur); } return true; }
void LoadVideoThread::loadFromVideo() { qDebug() << "Start loading video..."; cv::VideoCapture cap; if(!cap.open(filePath.toStdString())) { emit completeLoading(false); } else { gtv->setFrameCount((int)cap.get(CV_CAP_PROP_FRAME_COUNT)); uint frameno = 0; for(;;) { cv::Mat frame; cap >> frame; if (!frame.data) { break; } frameno++; cv::Mat rgbFrame; cv::cvtColor(frame, rgbFrame, CV_BGR2RGB); // append it to data model gtv->appendFrame(rgbFrame); } cv::Mat truth((int)cap.get(CV_CAP_PROP_FRAME_HEIGHT), (int)cap.get(CV_CAP_PROP_FRAME_WIDTH), CV_8UC1, cv::Scalar(0)); gtv->initializeGroundtruth(frameno, truth); emit completeLoading(true); } exit(0); }
V fwh(ST s){O b=pop(s),c=top(s);if(b->t!=TCB)TE;while(truth(c)){excb(b);c=top(s);}dlo(b);} //while loop
V fif(ST s){O f=pop(s),t=pop(s),c=pop(s),r;r=truth(c)?t:f;if(r->t==TCB)excb(r);else psh(s,dup(r));dlo(c);dlo(t);dlo(f);} //if stmt
V mod(ST s){ O o,a,b=pop(s);a=pop(s); if(a->t==TA&&b->t==TCB){ST na=newst(BZ);O on=v['n'];rev(a->a);while(len(a->a)){ v['n']=pop(a->a);excb(b);if(truth(o=pop(s)))psh(na,dup(v['n']));dlo(o);dlo(v['n']);} v['n']=on;dlo(a);dlo(b);psh(s,newoa(na)); //filter }else{if(a->t!=b->t||a->t==TCB||b->t==TCB)TE;psh(s,modfn[a->t](a,b));dlo(a);dlo(b);}} //mod
object* eval_cc(object* x, environment* env, continuation* cc) { // // The purpose of the while loop is to allow tail recursion. // The idea is that in a tail recursive position, we do "x = ..." // and loop, rather than doing "return eval(...)". // while (true) { if (is_symbol(x)) // VARIABLE { symbol* sym = dynamic_cast<symbol*>(x); DEBUG("eval_cc sym", sym); return cc->apply(env->lookup(sym)); } else if (!is_pair(x)) // CONSTANT { return cc->apply(x); } else { object* fn = car(x); object* args = cdr(x); if (is_symbol(fn, "quote")) // QUOTE { return cc->apply(car(args)); } else if (is_symbol(fn, "begin")) // BEGIN { continuation* cc2 = new continuation_begin(cdr(args), env, cc); return eval_cc(car(args), env, cc2); } else if (is_symbol(fn, "define")) // DEFINE { if (is_pair(car(args))) { object* lx = cons(symbol::get("lambda"), cons(cdr(car(args)), cdr(args))); continuation_define* cc2 = new continuation_define(car(car(args)), env, cc); return eval_cc(lx, env, cc2); } else { continuation_define* cc2 = new continuation_define(first(args), env, cc); return eval_cc(second(args), env, cc2); } } else if (is_symbol(fn, "set!")) // SET! { return env->set(first(args), eval(second(args), env)); } else if (is_symbol(fn, "if")) // IF { object* test = eval(first(args), env); x = truth(test) ? second(args) : third(args); } #if 0 else if (is_symbol(fn, "cond")) // COND { x = reduceCond(args, env); } #endif else if (is_symbol(fn, "lambda")) // LAMBDA { return cc->apply(new closure(first(args), second(args), env)); } #if 0 else if (is_symbol(fn, "macro")) { // FIXME // return Macro(new macro(car(args), cdr(args), env); } #endif else { DEBUG("#0 x", x); DEBUG("#1 fn", fn); DEBUG("#2 args", args); DEBUG("#3 cc", cc); continuation* cc2 = new continuation_procedure(args, env, cc); return eval_cc(fn, env, cc2); } } } }
#include <stdlib.h> #include <math.h> #include <primitives.h> #include <stack_machine/common.h> #include <stack_machine/context.h> #include <stack_machine/entry.h> #include <stack_machine/error.h> #define truth(x) ((x) ? -1 : 0) arity2stackop(__EQ, truth(x1 == x2)) arity2stackop(__NEQ, truth(x1 != x2)) arity2stackop(__LT, truth(x1 < x2)) arity2stackop(__GT, truth(x1 > x2)) arity2stackop(__ULT, truth((unsigned int)x1 < (unsigned int)x2)) arity2stackop(__UGT, truth((unsigned int)x1 > (unsigned int)x2)) arity1stackop(__ISNEG, truth(x1 < 0)) arity1stackop(__ISZERO, truth(x1 == 0)) arity1stackop(__ISNOTZERO, truth(x1 != 0)) arity1stackop(__ISPOS, truth(x1 > 0)) arity3stackop(__WITHIN, truth(x1 >= x2 && x1 < x3)) void init_comparison_words(context_t *ctx) { hashtable_t *htbl = ctx->exe_tok; add_primitive(htbl, "=", __EQ, "( x1 x2 -- f )", "compares top two stack elements, returns true flag if equal, false otherwise."); add_primitive(htbl, "<>", __NEQ, "( x1 x2 -- f )", "compares top two stack elements, returns true flag if different, false otherwise."); add_primitive(htbl, "<", __LT, "( n1 n2 -- f )", "compares signed numbers n1 with n2, returns true if n1 is less then n2."); add_primitive(htbl, ">", __GT, "( n1 n2 -- f )", "compares signed numbers n1 with n2, returns true if n1 is greater then n2."); add_primitive(htbl, "U<", __ULT, "( u1 u2 -- f )", "compares unsigned numbers u1 with u2, returns true if n1 is lower then n2.");