//////////////////////////////////////////////////////////////////////////////// //! Display callback //////////////////////////////////////////////////////////////////////////////// void display() { // run CUDA kernel to generate vertex positions boost::shared_ptr<thrust::device_vector<ms::point> > dv = runCuda(); if (!dv) return; ms::gl_buffer<ms::point> glb(dv->size()); glb << *dv; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set view matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, translate_z); glRotatef(rotate_x, 1.0, 0.0, 0.0); glRotatef(rotate_y, 0.0, 1.0, 0.0); // render from the vbo glBindBuffer(GL_ARRAY_BUFFER, glb.buffer()); glVertexPointer(3, // GLint size GL_FLOAT, // GLenum type 24, // GLsizei stride 0); // offset // assert (displayable.size_bytes == mesh_width * mesh_height * sizeof(mephitis::point)); //glColor3f(1.0, 1.0, 1.0); glColorPointer(3, GL_FLOAT, 24, (const GLvoid*)(sizeof(float) * 3)); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glDrawArrays(GL_POINTS, // GLenum mode 0, // GLint first glb.size() // GLsizei count ); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glutSwapBuffers(); glutPostRedisplay(); }
ExecStatus ChannelBool<View>::propagate(Space& home, const ModEventDelta&) { running = true; if (zeros.size() > 0) { BndSetRanges zi(zeros); GECODE_ME_CHECK(y.excludeI(home, zi)); zeros.init(home); } if (ones.size() > 0) { BndSetRanges oi(ones); GECODE_ME_CHECK(y.includeI(home, oi)); ones.init(home); } running = false; if (delta.glbMin() != 1 || delta.glbMax() != 0) { if (!delta.glbAny()) { for (int i=delta.glbMin(); i<=delta.glbMax(); i++) GECODE_ME_CHECK(x[i].one(home)); } else { GlbRanges<View> glb(y); for (Iter::Ranges::ToValues<GlbRanges<View> > gv(glb); gv(); ++gv) { GECODE_ME_CHECK(x[gv.val()].one(home)); } } } if (delta.lubMin() != 1 || delta.lubMax() != 0) { if (!delta.lubAny()) { for (int i=delta.lubMin(); i<=delta.lubMax(); i++) GECODE_ME_CHECK(x[i].zero(home)); } else { int cur = 0; for (LubRanges<View> lub(y); lub(); ++lub) { for (; cur < lub.min(); cur++) { GECODE_ME_CHECK(x[cur].zero(home)); } cur = lub.max() + 1; } for (; cur < x.size(); cur++) { GECODE_ME_CHECK(x[cur].zero(home)); } } } new (&delta) SetDelta(); return y.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX; }
int main(int argc, char*argv[]){ int failed=0; uint32_t i; uint32_t result; uint32_t out; int aaa[1024]; int k=0; int m=0; int del = 0; int table[128]; if(argc < 4){ printf("few args!!\n"); return 1; } i=0; while(i<128){ table[i]=0; i++; } int offset = atoi(argv[1]); int offset_term = atoi(argv[2]); i=(127<<23) + (offset << 13); int j=0 - (atoi(argv[3])); int dist=1000; int best=0; while(offset < offset_term){ dist=1000; j=0 - (atoi(argv[3])); while(j < atoi(argv[3]) + 1){ k=0; i=(127<<23) + (offset << 13); while(k < 8192*1024){ result=finv_s(i); out = finv(i,j); del = out - result; /*if(del > 4 || del < -4){ printf("offset: %d\n",offset); printf("del: %d\n",del); printbin(i); printbin(out); printbin(result); return 0; }*/ table[del+64] = table[del+64]+1; k++; i++; } printtable(table); return 1; if(distri(table) < dist){ best = j; dist = distri(table); } m=0; while(m<128){ table[m]=0; m++; } j++; } k=0; i=(127<<23) + (offset << 13); while(k < 8192){ result=finv_s(i); out = finv(i,best); del = out - result; table[del+64] = table[del+64]+1; k++; i++; } //print23bin(ctou(dummy[offset])); //printtable(table); //printf("%d\n",lub(table)); aaa[offset] = 0 - ((lub(table)+glb(table)) /2); /*m=0; while(m<128){ table[m]=0; m++; }*/ if(dist < 10){ fprintf(stderr,"clear: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table)); }else{ fprintf(stderr,"FAILED...: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table)); failed++; } fprintf(stderr,"sinchoku...%d/%d\n",offset-atoi(argv[1]),atoi(argv[2])-atoi(argv[1])); incdecprint2(dummy2,best,offset); m=0; while(m<128){ table[m]=0; m++; } offset++; } offset=atoi(argv[1]); while(offset < atoi(argv[2])){ incdecprint(dummy,aaa[offset],offset); offset++; } //printf("best case: %d dist: %d\n",best,dist); fprintf(stderr,"failed cases: %d/%d\n",failed,atoi(argv[2])-atoi(argv[1])); return 0; }
/* Entry point */ int main(int argc, char** argv) { /* * Initialize Logging */ google::InitGoogleLogging(""); /* * Environment Wrangling */ const char *home = std::getenv("HOME"); boost::program_options::variables_map vm; std::string name = ""; boost::filesystem::path config_file; /* * Define argument parsing description for program_options */ /* * Parse arguments from command line and configuration file */ boost::program_options::options_description rr( "World Router" ); boost::program_options::options_description glb ( "Global Options " ); boost::program_options::options_description all ( "World Router Options" ); boost::program_options::options_description named ("Named Options"); rr.add_options() ( "help,h", "Display help message" ) ( "name,n", boost::program_options::value<std::string>(),"Name of Router. \nDefault: Required") ( "config,c", boost::program_options::value<std::string>(), "Config File: \nDefault: Required") ( "primary,p", boost::program_options::value<std::string>()->implicit_value("true"), "Primary Broker. \nDefault: false") ; glb.add_options() ( "global.broker", boost::program_options::value<std::string>(), "" ) ; /* * Create groups */ all.add(rr); all.add(glb); /* * Create WorldRouter Object * */ WorldRouter router; try { /* * Checked Argument Wrangling */ boost::program_options::store( boost::program_options::parse_command_line(argc, argv, all), vm ); boost::program_options::notify(vm); /* * Special cases */ if ( vm.count("help") ) { std::cout << rr << std::endl; return 1; } /* * Name / Id must * Might attempt to register with msg broker a named * queue */ if ( vm.count("name") ) name = vm["name"].as<std::string>(); if ( vm.count("config") ) config_file = vm["config"].as<std::string>(); if ( name.empty() || name == "" ) throw std::runtime_error("router name is required, specify with --name"); if ( ! boost::filesystem::exists(config_file)) throw std::runtime_error("config file [" + config_file.string() + "] does not exist"); /* * Parse the config file */ std::ifstream config_file_stream(config_file.string()); /* * Because We want to be able to different sections based on name */ named.add_options() ( (name+".master.q,i").c_str(), boost::program_options::value<std::string>(), "In Queue. \nDefault: master.q") ( (name+".internal.wrq,i").c_str(), boost::program_options::value<std::string>(), "In Queue. \nDefault: internal.wrq") ; all.add(named); /* * And we want the named to only be available via the config file */ boost::program_options::store( boost::program_options::parse_config_file(config_file_stream, all, true), vm ); boost::program_options::notify(vm); /* * Register Configuration */ router.registerConfig(vm); /* * Create session * 1) establish connection to broker * 2) create session * 3) create queue if primary ( reciever ) * if primary, queue must not be present * if NOT primary, queue MUST be present * */ router.establishSession(); router.run(); } catch(const std::exception& error) { std::cerr << "Exception: " << error.what() << std::endl; google::FlushLogFiles(google::INFO); } LOG(INFO) << "All Done!"; google::FlushLogFiles(google::INFO); return 0; }
ExecStatus Weights<View>::propagate(Space& home, const ModEventDelta&) { ModEvent me = ME_SET_NONE; if (!x.assigned()) { // Collect the weights of the elements in the unknown set in an array int size = elements.size(); Region r(home); int* currentWeights = r.alloc<int>(size); UnknownRanges<View> ur(x); Iter::Ranges::ToValues<UnknownRanges<View> > urv(ur); for (int i=0; i<size; i++) { if (!urv() || elements[i]<urv.val()) { currentWeights[i] = 0; } else { assert(elements[i] == urv.val()); currentWeights[i] = weights[i]; ++urv; } } // Sort the weights of the unknown elements IntLess il; Support::quicksort<int>(currentWeights, size, il); // The maximum number of elements that can still be added to x int delta = static_cast<int>(std::min(x.unknownSize(), x.cardMax() - x.glbSize())); // The weight of the elements already in x GlbRanges<View> glb(x); int glbWeight = weightI<GlbRanges<View> >(elements, weights, glb); // Compute the weight of the current lower bound of x, plus at most // delta-1 further elements with smallest negative weights. This weight // determines which elements in the upper bound cannot possibly be // added to x (those whose weight would exceed the capacity even if // all other elements are minimal) int lowWeight = glbWeight; for (int i=0; i<delta-1; i++) { if (currentWeights[i] >= 0) break; lowWeight+=currentWeights[i]; } // Compute the lowest possible weight of x. If there is another element // with negative weight left, then add its weight to lowWeight. // Otherwise lowWeight is already the lowest possible weight. int lowestWeight = lowWeight; if (delta>0 && currentWeights[delta-1]<0) lowestWeight+=currentWeights[delta-1]; // If after including the minimal number of required elements, // no more element with negative weight is available, then // a tighter lower bound can be computed. if ( (x.cardMin() - x.glbSize() > 0 && currentWeights[x.cardMin() - x.glbSize() - 1] >= 0) || currentWeights[0] >= 0 ) { int lowestPosWeight = glbWeight; for (unsigned int i=0; i<x.cardMin() - x.glbSize(); i++) { lowestPosWeight += currentWeights[i]; } lowestWeight = std::max(lowestWeight, lowestPosWeight); } // Compute the highest possible weight of x as the weight of the lower // bound plus the weight of the delta heaviest elements still in the // upper bound. int highestWeight = glbWeight; for (int i=0; i<delta; i++) { if (currentWeights[size-i-1]<=0) break; highestWeight += currentWeights[size-i-1]; } // Prune the weight using the computed bounds GECODE_ME_CHECK(y.gq(home, lowestWeight)); GECODE_ME_CHECK(y.lq(home, highestWeight)); // Exclude all elements that are too heavy from the set x. // Elements are too heavy if their weight alone already // exceeds the remaining capacity int remainingCapacity = y.max()-lowWeight; UnknownRanges<View> ur2(x); Iter::Ranges::ToValues<UnknownRanges<View> > urv2(ur2); OverweightValues<Iter::Ranges::ToValues<UnknownRanges<View> > > ov(remainingCapacity, elements, weights, urv2); Iter::Values::ToRanges<OverweightValues< Iter::Ranges::ToValues<UnknownRanges<View> > > > ovr(ov); me = x.excludeI(home, ovr); GECODE_ME_CHECK(me); } if (x.assigned()) { // If x is assigned, just compute its weight and assign y. GlbRanges<View> glb(x); int w = weightI<GlbRanges<View> >(elements, weights, glb); GECODE_ME_CHECK(y.eq(home, w)); return home.ES_SUBSUMED(*this); } return me_modified(me) ? ES_NOFIX : ES_FIX; }