/* Checks state safety. Returns true if safe, else false. */ bool is_safe() { /* Work vector, length m. */ int work[RESOURCES]; /* Finish vector, length n. */ bool finish[CUSTOMERS]; /* Initialize work vector = available vector. */ copy_array(available, work); /* Set all elements in finish vector to false. */ set_all_false(finish); /* Find index i such that finish[i] == false && need[i] <= work. */ int i = find_i(work, finish); /* If no such i exists, check if all finish elements are true. */ if (i == -1) { //such I does not exist if (all_true(finish) == true) { /* The system is in a safe state! */ return true; } } else { /* work = work + allocation */ add_vectors(work, allocation[i]); finish[i] = true; /* Go to step 2. */ i = find_i(work, finish); } }
void guiRenderer2D::on_menu_popup_reset_mask() { if(m_frameManager->isConnectedDSA()) { std::vector<bool> all_true(m_frameManager->getNumCells(), true); m_frameManager->setDynamicMask(all_true); } else { Gtk::MessageDialog dialog("DSA is not connected!", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); dialog.run(); } }
static constexpr bool all_true (B && b1, Bs&& ... bs) { return std::forward<B>(b1) && all_true(std::forward<Bs>(bs)...); }
static constexpr bool all_true (bool const& b1, BOOL&& ... bs) { return b1 && all_true (std::forward<BOOL>(bs)...); }
//// //// class ConsTracking //// vector<vector<Event> > ConsTracking::operator()(TraxelStore& ts) { cout << "-> building energy functions " << endl; double detection_weight = 10; Traxels empty; boost::function<double(const Traxel&, const size_t)> detection, division; boost::function<double(const double)> transition; bool use_classifier_prior = false; Traxel trax = *(ts.begin()); FeatureMap::const_iterator it = trax.features.find("detProb"); if(it != trax.features.end()) { use_classifier_prior = true; } if (use_classifier_prior) { LOG(logINFO) << "Using classifier prior"; detection = NegLnDetection(detection_weight); } else if (use_size_dependent_detection_) { LOG(logINFO) << "Using size dependent prior"; vector<double> means; if (means_.size() == 0 ) { for(int i = 0; i<max_number_objects_+1; ++i) { means.push_back(i*avg_obj_size_); LOG(logINFO) << "mean[" << i << "] = " << means[i]; } } else { assert(sigmas_.size() != 0); for(int i = 0; i<max_number_objects_+1; ++i) { means.push_back(means_[i]); LOG(logINFO) << "mean[" << i << "] = " << means[i]; } } vector<double> sigma2; if (sigmas_.size() == 0) { double s2 = (avg_obj_size_*avg_obj_size_)/4.0; if (s2 < 0.0001) { s2 = 0.0001; } for(int i = 0; i<max_number_objects_+1; ++i) { sigma2.push_back(s2); LOG(logINFO) << "sigma2[" << i << "] = " << sigma2[i]; } } else { for (int i = 0; i<max_number_objects_+1; ++i) { sigma2.push_back(sigmas_[i]); LOG(logINFO) << "sigma2[" << i << "] = " << sigma2[i]; } } for(TraxelStore::iterator tr = ts.begin(); tr != ts.end(); ++tr) { Traxel trax = *tr; FeatureMap::const_iterator it = trax.features.find("count"); if(it == trax.features.end()) { throw runtime_error("get_detection_prob(): cellness feature not in traxel"); } double vol = it->second[0]; vector<double> detProb; detProb = computeDetProb(vol,means,sigma2); feature_array detProbFeat(feature_array::difference_type(max_number_objects_+1)); for(int i = 0; i<=max_number_objects_; ++i) { double d = detProb[i]; if (d < 0.01) { d = 0.01; } else if (d > 0.99) { d = 0.99; } LOG(logDEBUG2) << "detection probability for " << trax.Id << "[" << i << "] = " << d; detProbFeat[i] = d; } trax.features["detProb"] = detProbFeat; ts.replace(tr, trax); } detection = NegLnDetection(detection_weight); // weight 1 } else { LOG(logINFO) << "Using hard prior"; // assume a quasi geometric distribution vector<double> prob_vector; double p = 0.7; // e.g. for max_number_objects_=3, p=0.7: P(X=(0,1,2,3)) = (0.027, 0.7, 0.21, 0.063) double sum = 0; for(double state = 0; state < max_number_objects_; ++state) { double prob = p*pow(1-p,state); prob_vector.push_back(prob); sum += prob; } prob_vector.insert(prob_vector.begin(), 1-sum); detection = bind<double>(NegLnConstant(detection_weight,prob_vector), _2); } LOG(logDEBUG1) << "division_weight_ = " << division_weight_; LOG(logDEBUG1) << "transition_weight_ = " << transition_weight_; division = NegLnDivision(division_weight_); transition = NegLnTransition(transition_weight_); cout << "-> building hypotheses" << endl; SingleTimestepTraxel_HypothesesBuilder::Options builder_opts(1, // max_nearest_neighbors max_dist_, true, // forward_backward with_divisions_, // consider_divisions division_threshold_ ); SingleTimestepTraxel_HypothesesBuilder hyp_builder(&ts, builder_opts); HypothesesGraph* graph = hyp_builder.build(); LOG(logDEBUG1) << "ConsTracking(): adding distance property to edges"; HypothesesGraph& g = *graph; g.add(arc_distance()).add(tracklet_intern_dist()).add(node_tracklet()).add(tracklet_intern_arc_ids()).add(traxel_arc_id()); property_map<arc_distance, HypothesesGraph::base_graph>::type& arc_distances = g.get(arc_distance()); property_map<node_traxel, HypothesesGraph::base_graph>::type& traxel_map = g.get(node_traxel()); bool with_optical_correction = false; Traxel some_traxel = (*traxel_map.beginValue()); if (some_traxel.features.find("com_corrected") != some_traxel.features.end()) { LOG(logINFO) << "optical correction enabled"; with_optical_correction = true; } for(HypothesesGraph::ArcIt a(g); a!=lemon::INVALID; ++a) { HypothesesGraph::Node from = g.source(a); HypothesesGraph::Node to = g.target(a); Traxel from_tr = traxel_map[from]; Traxel to_tr = traxel_map[to]; if (with_optical_correction) { arc_distances.set(a, from_tr.distance_to_corr(to_tr)); } else { arc_distances.set(a, from_tr.distance_to(to_tr)); } } //border_width_ is given in normalized scale, 1 corresponds to a maximal distance of dim_range/2 boost::function<double(const Traxel&)> appearance_cost_fn, disappearance_cost_fn; LOG(logINFO) << "using border-aware appearance and disappearance costs, with absolute margin: " << border_width_; appearance_cost_fn = SpatialBorderAwareWeight(appearance_cost_, border_width_, false, // true if relative margin to border fov_); disappearance_cost_fn = SpatialBorderAwareWeight(disappearance_cost_, border_width_, false, // true if relative margin to border fov_); cout << "-> init ConservationTracking reasoner" << endl; ConservationTracking pgm( max_number_objects_, detection, division, transition, forbidden_cost_, ep_gap_, with_tracklets_, with_divisions_, disappearance_cost_fn, appearance_cost_fn, true, // with_misdetections_allowed true, // with_appearance true, // with_disappearance transition_parameter_, with_constraints_ ); cout << "-> formulate ConservationTracking model" << endl; pgm.formulate(*graph); cout << "-> infer" << endl; pgm.infer(); cout << "-> conclude" << endl; pgm.conclude(*graph); cout << "-> storing state of detection vars" << endl; last_detections_ = state_of_nodes(*graph); cout << "-> pruning inactive hypotheses" << endl; prune_inactive(*graph); cout << "-> constructing unresolved events" << endl; boost::shared_ptr<std::vector< std::vector<Event> > > ev = events(*graph); if (max_number_objects_ > 1 && with_merger_resolution_ && all_true(ev->begin(), ev->end(), has_data<Event>)) { cout << "-> resolving mergers" << endl; MergerResolver m(graph); FeatureExtractorMCOMsFromMCOMs extractor; DistanceFromCOMs distance; FeatureHandlerFromTraxels handler(extractor, distance); calculate_gmm_beforehand(*graph, 1, number_of_dimensions_); m.resolve_mergers(handler); HypothesesGraph g_res; resolve_graph(*graph, g_res, transition, ep_gap_, with_tracklets_, transition_parameter_, with_constraints_); prune_inactive(*graph); cout << "-> constructing resolved events" << endl; boost::shared_ptr<std::vector< std::vector<Event> > > multi_frame_moves = multi_frame_move_events(*graph); cout << "-> merging unresolved and resolved events" << endl; return *merge_event_vectors(*ev, *multi_frame_moves); } else { return *ev; } }
bool _sctype_apply(lua_State* state, index_tuple<Indexes...>, invoke_signature_type<R, Args...>) { return all_true(lua_type_traits<Args>::strictCheckType(state, Indexes)...); }
template<class...Args>bool all_true(bool b, Args... args) { return b && all_true(args...); }
static inline bool operator_Le(Ty1&& x, Ty2&& y) { return all_true(std::forward<Ty1>(x) <= std::forward<Ty2>(y)); }