Example #1
0
static SB_INLINE void bitset_iter(BitSet& bs, int (*app)(uint32_t e, void* stuff1), void* stuff2) {
    BitSet::iterator i;
    for(i = bs.begin(); i != bs.end(); i++) {
        if((app(*i, stuff2)) != 0) {
            break;
        }
    }
}
Example #2
0
// populates el (assumed to be pre-allocated adequately by caller)
// with list of members in bitset bs.
static SB_INLINE void bitset_get_list_here(BitSet& bs, uint32_t *el) {
    int j = 0;
    BitSet::iterator i;
    for(i = bs.begin(); i != bs.end(); i++) {
        el[j] = *i;
        j++;
    }
}
void BitVector<dim>::unslice(BitSet<dim> t,size_t new_size)
{
  BitSet<dim> result;
  for (typename BitSet<dim>::iterator it=t.begin(); it();
       d_data>>=1,++it)
    result.set(*it,d_data[0]);
  d_data=result;
  d_size=new_size;
}
Example #4
0
FncKhunTucker::FncKhunTucker(const NormalizedSystem& sys, Function& _df, Function** _dg, const IntervalVector& current_box, const BitSet& active) :
								Fnc(1,1), nb_mult(0), // **tmp**
								n(sys.nb_var), sys(sys), df(_df), dg(active.size()), active(active),
								eq(BitSet::empty(sys.f_ctrs.image_dim())),
								ineq(BitSet::empty(sys.f_ctrs.image_dim())),
								bound_left(BitSet::empty(sys.nb_var)),
								bound_right(BitSet::empty(sys.nb_var)) {

	int l=1; // lambda0

	if (_dg==NULL && !active.empty()) {
		ibex_error("[FncKhunTucker] an unconstrained system cannot have active constraints");
	}

	unsigned int i=0; // index of a constraint in the active set
	for (BitSet::const_iterator c=active.begin(); c!=active.end(); ++c, ++i) {
		dg.set_ref(i,*_dg[c]);
		if (sys.ops[c]==EQ) eq.add(i);
		else ineq.add(i);
		//cout << " constraint n°" << c << " active\n";
	}
	l+=active.size();

	for (int j=0; j<sys.box.size(); j++) {
		if (current_box[j].lb() <= sys.box[j].lb()) {
			bound_left.add(j);
			//cout << " left bound n°" << j << " active\n";
			l++;
		}
		if (current_box[j].ub() >= sys.box[j].ub()) {
			bound_right.add(j);
			//cout << " right bound n°" << j << " active\n";
			l++;
		}

	}

	(int&) nb_mult = l;

	(int&) _nb_var = n + l;

	assert(_nb_var == sys.nb_var + eq.size() + ineq.size() + bound_left.size() + bound_right.size() + 1);

	(Dim&) _image_dim = Dim(_nb_var, 1);

}
Example #5
0
// spit out members of the set
static SB_INLINE void bitset_spit(BitSet& bs) {
    BitSet::iterator i;
    for(i = bs.begin(); i != bs.end(); i++) {
        std::cout << *i << std::endl;
    }
}
Example #6
0
// merge bsDest with bsSrc and place result in bsDest
static SB_INLINE void bitset_collect(BitSet& bsDest, BitSet& bsSrc) {
    bsDest.insert(bsSrc.begin(), bsSrc.end());
}
int LinearizerDuality::linearize(const IntervalVector& box, LPSolver& lp_solver, BoxProperties& prop)  {
	// ========= get active constraints ===========
	/* Using system cache seems not interesting. */
	//BxpSystemCache* cache=(BxpSystemCache*) prop[BxpSystemCache::get_id(sys)];
	BxpSystemCache* cache=NULL;
	//--------------------------------------------------------------------------

	BitSet* active;

	if (cache!=NULL) {
		active = &cache->active_ctrs();
	} else {
		active = new BitSet(sys.active_ctrs(box));
	}
	// ============================================

	size_t n = sys.nb_var;
	size_t m = sys.f_ctrs.image_dim();
	size_t n_total = n +  m*n;

	int nb_ctr=0; // number of inequalities added in the LP solver

//	BxpLinearRelaxArgMin* argmin=(BxpLinearRelaxArgMin*) prop[BxpLinearRelaxArgMin::get_id(sys)];
//
//	if (argmin && argmin->argmin()) {
//		pt=*argmin->argmin();
//	} else
		pt=box.mid();

	if (!active->empty()) {

		//IntervalMatrix J=cache? cache->active_ctrs_jacobian() : sys.f_ctrs.jacobian(box,active);
		//IntervalMatrix J=sys.f_ctrs.jacobian(box,*active);
		IntervalMatrix J(active->size(),n); // derivatives over the box
		sys.f_ctrs.hansen_matrix(box,pt,J,*active);

		if (J.is_empty()) {
			if (cache==NULL) delete active;
			return -1;
		}

		// the evaluation of the constraints in the point
		IntervalVector gx(sys.f_ctrs.eval_vector(pt,*active));
		if (gx.is_empty()) {
			if (cache==NULL) delete active;
			return 0;
		}


		int i=0; // counter of active constraints
		for (BitSet::iterator c=active->begin(); c!=active->end(); ++c, i++)  {

			if (!sys.f_ctrs.deriv_calculator().is_linear[c]) {
				for (size_t j=0; j<n; j++) {
					Vector row(n_total,0.0);
					row[j]=1;
					row[n + c*n +j]=1;

					double rhs = pt[j] - lp_solver.get_epsilon();

					lp_solver.add_constraint(row, LEQ, rhs);
					nb_ctr++;
				}
			}

			Vector row(n_total,0.0);
			row.put(0,J[i].lb());

			IntervalVector gl(J[i].lb());

			Vector diam_correctly_rounded = (IntervalVector(J[i].ub())-gl).lb();

			for (size_t j=0; j<n; j++) {
				if (diam_correctly_rounded[j]<0)
					ibex_error("negative diameter");
			}

			row.put(n + c*n,-diam_correctly_rounded);

			double rhs = (-gx[i] + (gl*pt)).lb()- lp_solver.get_epsilon();

			lp_solver.add_constraint(row, LEQ, rhs);
			nb_ctr++;
		}
	}

	if (cache==NULL) delete active;
	return nb_ctr;
}
Example #8
0
static SB_INLINE uint32_t bitset_choose(BitSet& bs) {
    if (bs.size() == 0) return 0xffffffff;
    return *(bs.begin());
}