void egg_test() { { BOOST_CHECK(lazy_minus(bll::_1, 2)(3|to_ref) == 1); BOOST_CHECK(lazy(base_minus())(bll::_1, 2)(3|to_ref) == 1); #if 0 // rejected BOOST_CHECK(lazy(base_minus(), bll_bind)(bll::_1, 2)(3|to_ref) == 1); #endif } { A a; BOOST_CHECK(lazy(&A::foo)(a, bll::_1)(3|to_ref) == 3); } { BOOST_CHECK(lazy_minus(bll::_1, bll::_2)(8|to_ref, 3|to_ref) == 5); BOOST_CHECK(lazy(base_minus())(bll::_1, bll::_2)(8|to_ref, 3|to_ref) == 5); } { BOOST_CHECK(lazy_minus(bll::_2, bll::_1)(8|to_ref, 3|to_ref) == -5); BOOST_CHECK(lazy_minus(8, bll::_1)(3|to_ref) == 5); } { BOOST_CHECK(lazy_minus(lazy_minus(bll::_1, 5), bll::_1)(2|to_ref) == 2-5-2); } { BOOST_CHECK(lazy_minus(lazy_minus(bll::_2, bll::_1), lazy_minus(bll::_1, bll::_2))(3|to_ref, 5|to_ref) == (5-3) - (3-5)); } { BOOST_CHECK( lazy(::big_arity())(1,2,3,bll::_1,5,6,bll::_2,8,9)(3|to_ref, 4|to_ref) == 13 ); } }
static constexpr auto apply(Id self, P p, F f) { auto x = eval_if(p(self.value), lazy(compose(f, get_value{}))(self), lazy(get_value{})(self) ); return test::identity(x); }
void operation(pnode t) //operation of segtree { if(!t)return; reset(t);//reset the value of current node assuming it now represents a single element of the array lazy(t->l); lazy(t->r);//imp:propagate lazy before combining t->l,t->r; combine(t,t->l,t); combine(t,t,t->r); }
void merge(pnode &t,pnode l,pnode r) //l->leftarray,r->rightarray,t->resulting array { lazy(l); lazy(r); if(!l || !r) t = l?l:r; else if(l->prior>r->prior)merge(l->r,l->r,r),t=l; else merge(r->l,l,r->l),t=r; upd_sz(t); operation(t); }
PST *add(PST *ptr, int lpos, int rpos, Data val, int la, int ra) { if (rpos <= la || ra <= lpos) return ptr; if (lpos <= la && ra <= rpos) { return new PST(value(ptr), lazy(ptr) + val, left(ptr), right(ptr)); } int mid = (la + ra) / 2; PST *l = add(left(ptr), lpos, rpos, val, la, mid); PST *r = add(right(ptr), lpos, rpos, val, mid, ra); int c = min(ra, rpos) - max(la, lpos); return new PST(value(ptr) + c * val, lazy(ptr), l, r); }
lbool lackr::operator() () { SASSERT(m_sat); if (!init()) return l_undef; const lbool rv = m_eager ? eager() : lazy(); if (rv == l_true) m_sat->get_model(m_model); CTRACE("lackr", rv == l_true, model_smt2_pp(tout << "abstr_model(\n", m_m, *(m_model.get()), 2); tout << ")\n"; );
void TestLazy() { //带参数的普通函数 int y = 4; auto lazyer1 = lazy(Foo, y); std::cout << lazyer1.Value() << std::endl; //不带参数的lamda Lazy<int> lazyer2 = lazy([]{return 12; }); std::cout << lazyer2.Value() << std::endl; //带参数的fucntion std::function < int(int) > f = [](int x){return x + 3; }; auto lazyer3 = lazy(f, 3); std::cout << lazyer3.Value() << std::endl; //延迟加载大对象 MyStruct t; t.Load(); }
void split(pnode t,pnode &l,pnode &r,int pos,int add=0) { if(!t)return void(l=r=NULL); lazy(t); int curr_pos = add + sz(t->l); if(curr_pos<=pos)//element at pos goes to left subtree(l) split(t->r,t->r,r,pos,curr_pos+1),l=t; else split(t->l,l,t->l,pos,add),r=t; upd_sz(t); operation(t); }
int main (int argc, char **argv) { IloEnv env; try { IloModel model(env); IloCplex cplex(env); if ( argc != 2 ) { usage (argv[0]); throw(-1); } IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2, lazy, cuts); cplex.extract(model); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts); cplex.solve(); env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "Solution value = " << cplex.getObjValue() << endl; IloNumArray vals(env); cplex.getValues(vals, var); env.out() << "Values = " << vals << endl; } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main
lazy lazy_rep::produce (lazy_type request, format fm) { if (request == type) return this; if ((request == LAZY_BOX) && (fm->type == FORMAT_CELL)) { format_cell fc= (format_cell) fm; lazy tmp= produce (LAZY_VSTREAM, make_format_vstream (fc->width, 0, 0)); return tmp->produce (request, fm); } if ((request == LAZY_BOX) && (fm->type == FORMAT_WIDTH)) { format_width fw= (format_width) fm; lazy tmp= produce (LAZY_VSTREAM, make_format_vstream (fw->width, 0, 0)); return tmp->produce (request, fm); } failed_error << "The lazy structure was " << ((tree) (*this)) << "\n"; failed_error << "The format was " << ((tree) fm) << "\n"; FAILED ("invalid production"); return lazy (); }
int main (int argc, char **argv) { char const *vmconfig = NULL; // Check command line length (exactly two arguments are required). if ( argc != 3 ) { usage (argv[0]); return -1; } // Pick up VMC from command line. vmconfig = argv[1]; // Solve the model. int exitcode = 0; IloEnv env; try { // Create and read the model. IloModel model(env); IloCplex cplex(model); IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, argv[2], obj, var, rng, sos1, sos2, lazy, cuts); cplex.extract(model); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts); // Load the virtual machine configuration. // This will force solve() to use parallel distributed MIP. cplex.readVMConfig(vmconfig); // Install logging info callback. IloNum lastObjVal = (obj.getSense() == IloObjective::Minimize ) ? IloInfinity : -IloInfinity; cplex.use(loggingCallback(env, var, -100000, lastObjVal, cplex.getCplexTime(), cplex.getDetTime())); // Turn off CPLEX logging cplex.setParam(IloCplex::Param::MIP::Display, 0); // Solve the problem and display some results. if ( cplex.solve() ) env.out() << "Solution value = " << cplex.getObjValue() << endl; else env.out() << "No solution" << endl; env.out() << "Solution status = " << cplex.getStatus() << endl; // Cleanup. cplex.end(); model.end(); } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; exitcode = -1; } catch (...) { cerr << "Unknown exception caught" << endl; exitcode = -1; } env.end(); return exitcode; } // END main
int solveCplex (char * str,ListStructure<number_element> * l) { IloEnv env; try { IloModel model(env); IloCplex cplex(env); IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, str, obj, var, rng, sos1, sos2, lazy, cuts); cplex.use(MyBranch(env, var)); cplex.use(MySelect(env)); cplex.setParam(IloCplex::MIPSearch, IloCplex::Traditional); cplex.extract(model); cplex.setParam(IloCplex::EpInt,0.000000000001); cplex.setParam(IloCplex::TiLim,120*60); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts); cplex.solve(); env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "Solution value = " << cplex.getObjValue() << endl; IloNumArray vals(env); cplex.getValues(vals, var); //IloObjective obj=cplex.getObjective(); env.out() << "Values = " << vals << endl; long long sum=0; int a=vals.getSize(); for(int i=0;i<a;i++){ int b=l->getSize(); number_element n=l->retrieve_K_esimo(i%b)->element; if(i<b){ if(vals[i]>0.9){ sum+=n.id; } }else{ if(vals[i]>0.9){ sum-=n.id; } } } } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); } // END main
int main (int argc, char **argv) { IloEnv env; try { IloModel model(env); IloCplex cplex(env); IloBool useLoggingCallback = IloFalse; IloBool useTimeLimitCallback = IloFalse; IloBool useAborter = IloFalse; if (( argc != 3 ) || ( strchr ("lat", argv[2][0]) == NULL ) ) { usage (argv[0]); throw(-1); } switch (argv[2][0]) { case 'l': useLoggingCallback = IloTrue; break; case 't': useTimeLimitCallback = IloTrue; break; case 'a': useAborter = IloTrue; break; default: break; } IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); IloCplex::Aborter myAborter; cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2, lazy, cuts); cplex.extract(model); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts); if ( useLoggingCallback ) { // Set an overall node limit in case callback conditions // are not met. cplex.setParam(IloCplex::Param::MIP::Limits::Nodes, 5000); IloNum lastObjVal = (obj.getSense() == IloObjective::Minimize ) ? IloInfinity : -IloInfinity; cplex.use(loggingCallback(env, var, -100000, lastObjVal, cplex.getCplexTime(), cplex.getDetTime())); // Turn off CPLEX logging cplex.setParam(IloCplex::Param::MIP::Display, 0); } else if ( useTimeLimitCallback ) { cplex.use(timeLimitCallback(env, cplex, IloFalse, cplex.getCplexTime(), 1.0, 10.0)); } else if ( useAborter ) { myAborter = IloCplex::Aborter(env); cplex.use(myAborter); // Typically, you would pass the Aborter object to // another thread or pass it to an interrupt handler, // and monitor for some event to occur. When it does, // call the Aborter's abort method. // // To illustrate its use without creating a thread or // an interrupt handler, abort immediately by calling // abort before the solve. // myAborter.abort(); } cplex.solve(); env.out() << endl; env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "CPLEX status = " << cplex.getCplexStatus() << endl; } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main
lazy box_rep::get_leaf_lazy () { failed_error << "The box is " << box (this) << "\n"; FAILED ("no lazy attached to this box"); return lazy (); }
MyStruct() { m_obj = lazy([]{return std::make_shared<BigObject>(); }); }
static constexpr auto apply(Xs xs, X x) { return lazy_cons(x, lazy(xs)); }
int main (int argc, char **argv) { IloEnv env; try { IloModel model(env); IloCplex cplex(env); if ( argc != 2 ) { usage (argv[0]); throw(-1); } IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2, lazy, cuts); /* Set the solution pool relative gap parameter to obtain solutions of objective value within 10% of the optimal */ cplex.setParam(IloCplex::Param::MIP::Pool::RelGap, 0.1); cplex.extract(model); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints(lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts(cuts); cplex.populate(); env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "Incumbent objective value = " << cplex.getObjValue() << endl; IloNumArray incvals(env); cplex.getValues(incvals, var); env.out() << "Incumbent values = " << incvals << endl << endl; /* Get the number of solutions in the solution pool */ int numsol = cplex.getSolnPoolNsolns(); env.out() << "The solution pool contains " << numsol << " solutions." << endl; /* Some solutions are deleted from the pool because of the solution pool relative gap parameter */ int numsolreplaced = cplex.getSolnPoolNreplaced(); env.out() << numsolreplaced << " solutions were removed due to the " "solution pool relative gap parameter." << endl; env.out() << "In total, " << numsol + numsolreplaced << " solutions were generated." << endl; /* Get the average objective value of solutions in the solution pool */ env.out() << "The average objective value of the solutions is " << cplex.getSolnPoolMeanObjValue() << "." << endl << endl; /* Write out the objective value of each solution and its difference to the incumbent */ for (int i = 0; i < numsol; i++) { /* Write out objective value */ env.out() << "Solution " << i << " with objective " << cplex.getObjValue(i) << " differs in "; IloNumArray vals(env); cplex.getValues(vals, var, i); /* Compute the number of variables that differ in the solution and in the incumbent */ int numdiff = 0; for (int j = 0; j < vals.getSize(); j++) { if ( fabs(vals[j] - incvals[j]) > EPSZERO ) numdiff++; } env.out() << numdiff << " of " << vals.getSize() << " variables." << endl; } } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main