Skip to content

Commit

Permalink
Commit #6feec93f4e7d15e364220294651002e59e0e9169 was unfortunately in…
Browse files Browse the repository at this point in the history
…complete. Fixing it. Add default constructor for Bitset
  • Loading branch information
Gilles Chabert committed Apr 1, 2019
1 parent cd03bef commit 850f804
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 30 deletions.
2 changes: 1 addition & 1 deletion plugins/sip/src/mitsos/ibex_BD_Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void BD_Factory::add_discretized_ctr(double eps_g) {
// with all previously existing combinations.
for (int j=0; j<sip.p; j++) {
//cout << " param n°" << j << "=" << sip.varset.param(j);
if (sip.sys.ctrs[c].f.used_vars[sip.varset.param(j)]) {
if (sip.sys.ctrs[c].f.used(sip.varset.param(j))) {
//cout << " **used**" << endl;
// for each box already inside the list...
for (list<Vector>::iterator it2=p_boxes.begin(); it2!=p_boxes.end(); it2=p_boxes.erase(it2)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/sip/src/mitsos/ibex_LLP_Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ LLP_Factory::LLP_Factory(const MitsosSIP& sip, int c, const Vector& xopt) : new_

// TODO: not the cleanest way!!
for (int j=0; j<sip.p; j++) {
if (sip.sys.ctrs[c].f.used_vars[sip.varset.param(j)]) {
if (sip.sys.ctrs[c].f.used(sip.varset.param(j))) {
param_LLP_var.add(j);
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/function/ibex_Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ibex_SymbolMap.h"
#include "ibex_ExprSubNodes.h"
#include "ibex_Fnc.h"
#include "ibex_BitSet.h"

#include <stdexcept>
#include <stdarg.h>
Expand Down Expand Up @@ -569,6 +570,15 @@ class Function : public Fnc {
*/
int nb_arg() const;

/**
* \brief Return true if the ith variable is used in the function.
*
* \warning The function is seen as a function from R^n to R^m. So, the
* ith variable is <b>not</b> the ith symbol.
*
*/
bool used(int i) const;

/**
* \brief Return the current number of nodes in the DAG.
*/
Expand Down Expand Up @@ -890,7 +900,7 @@ class Function : public Fnc {
void decorate(const Array<const ExprSymbol>& x, const ExprNode& y);

Array<const ExprSymbol> symbs; // to retrieve symbol (node)s by appearing order.
std::vector<bool> is_used; // tells whether the i^th component is used.
BitSet is_used; // tells whether the i^th component is used.

// only generated if required
Function** comp; // the components. ==this if output_size()==1.
Expand Down Expand Up @@ -945,6 +955,10 @@ inline int Function::nb_arg() const {
return symbs.size();
}

inline bool Function::used(int i) const {
return is_used[i];
}

inline const Array<const ExprSymbol>& Function::args() const {
return symbs;
}
Expand Down
7 changes: 4 additions & 3 deletions src/function/ibex_FunctionBuild.cpp_
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ void Function::init(const Array<const ExprSymbol>& x, const ExprNode& y, const c
// ExprNAryOp* nary_op = dynamic_cast<const ExprNA>)
// }

BitSet _used_vars(_nb_var);

FindInputsUsed fsu(x, y, __symbol_index, _used_vars);
for (BitSet::const_iterator it=_used_vars.begin(); it!=_used_vars.end(); ++it) {
is_used.resize(_nb_var);

FindInputsUsed fsu(x, y, __symbol_index, is_used);
for (BitSet::const_iterator it=is_used.begin(); it!=is_used.end(); ++it) {
((vector<int>&) used_vars).push_back((int) it);
}

Expand Down
13 changes: 9 additions & 4 deletions src/tools/ibex_BitSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ using namespace std;
namespace ibex {

void BitSet::resize(int n) {
BitSet b(*this);
bitset.destroy();
bitset.initialise(n,0);
(*this) |= b;

if (initialized()) {
BitSet b(*this);
bitset.destroy();
bitset.initialise(n,0);
(*this) |= b;
} else
bitset.initialise(n,0);
}

BitSet BitSet::compose(const BitSet& b) const {
assert(initialized() && b.initialized());
assert(b.bitset.max() < size());

BitSet b2(size());
Expand Down
82 changes: 62 additions & 20 deletions src/tools/ibex_BitSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ namespace ibex {
class BitSet {
public:

/**
* \brief Create an uninitialized bitset.
*
* \warning Must be followed by a call to resize(...) !
*/
BitSet();

/**
* \brief Create an "empty" bitset () of capacity n.
*
Expand All @@ -58,7 +65,8 @@ class BitSet {
BitSet(const int n, const int* l);

/**
* \brief Change the capacity
* \brief Initialize a bitset or change the capacity
*
*/
void resize(int n);

Expand Down Expand Up @@ -224,8 +232,12 @@ class BitSet {
*/
iterator end() const;

protected:

bool initialized() const;

private:

Mistral::BitSet bitset;

};
Expand All @@ -247,6 +259,8 @@ std::ostream& operator<<(std::ostream& os, const BitSet& b);

/*================================== inline implementations ========================================*/

inline BitSet::BitSet() : bitset() { }

inline BitSet::BitSet(int n) : bitset(0,n-1,Mistral::BitSet::empt) { }

inline BitSet::BitSet(const BitSet& b) : bitset(b.bitset) { }
Expand All @@ -267,64 +281,92 @@ inline BitSet BitSet::singleton(int n, int i) {
return b;
}

inline bool BitSet::operator==(const BitSet& b) { return bitset==b.bitset; }
inline bool BitSet::operator==(const BitSet& b) {
assert(initialized() && b.initialized());
return bitset==b.bitset;
}

inline bool BitSet::operator!=(const BitSet& b) { return bitset!=b.bitset; }
inline bool BitSet::operator!=(const BitSet& b) {
assert(initialized() && b.initialized());
return bitset!=b.bitset;
}

inline BitSet& BitSet::operator=(const BitSet& b) { bitset=b.bitset; return *this; }
inline BitSet& BitSet::operator=(const BitSet& b) {
assert(initialized() && b.initialized());
bitset=b.bitset;
return *this;
}

inline BitSet& BitSet::operator&=(const BitSet& b) { bitset.intersect_with(b.bitset); return *this; }
inline BitSet& BitSet::operator&=(const BitSet& b) {
assert(initialized() && b.initialized());
bitset.intersect_with(b.bitset);
return *this;
}

inline BitSet& BitSet::operator|=(const BitSet& b) { bitset.union_with(b.bitset); return *this; }
inline BitSet& BitSet::operator|=(const BitSet& b) {
assert(initialized() && b.initialized());
bitset.union_with(b.bitset);
return *this;
}

inline int BitSet::min() const { return bitset.min(); }
inline int BitSet::min() const { assert(initialized()); return bitset.min(); }

inline int BitSet::max() const { return bitset.max(); }
inline int BitSet::max() const { assert(initialized()); return bitset.max(); }

inline void BitSet::remove(const int elt) { bitset.fast_remove(elt); }
inline void BitSet::remove(const int elt) { assert(initialized()); bitset.fast_remove(elt); }

inline int BitSet::next(const int elt) const { return bitset.next(elt); }
inline int BitSet::next(const int elt) const { assert(initialized()); return bitset.next(elt); }

inline int BitSet::size() const { return (int) bitset.size(); }
inline int BitSet::size() const { assert(initialized()); return (int) bitset.size(); }

inline void BitSet::add(const int elt) { bitset.fast_add(elt); }
inline void BitSet::add(const int elt) { assert(initialized()); bitset.fast_add(elt); }

inline bool BitSet::empty() const { return bitset.empty(); }
inline bool BitSet::empty() const { assert(initialized()); return bitset.empty(); }

inline void BitSet::fill(const int lb, const int ub) { bitset.fill(lb,ub); }
inline void BitSet::fill(const int lb, const int ub) { assert(initialized()); bitset.fill(lb,ub); }

inline void BitSet::clear() { bitset.clear(); }
inline void BitSet::clear() { assert(initialized()); bitset.clear(); }

inline bool BitSet::operator[](const int i) const { return bitset.fast_contain(i); }
inline bool BitSet::operator[](const int i) const { assert(initialized()); return bitset.fast_contain(i); }

inline void BitSet::diff(const BitSet& b) { bitset.setminus_with(b.bitset); }
inline void BitSet::diff(const BitSet& b) {
assert(initialized() && b.initialized());
bitset.setminus_with(b.bitset);
}

inline BitSet operator&(const BitSet& b1, const BitSet& b2) { return BitSet(b1)&=b2; }

inline BitSet operator|(const BitSet& b1, const BitSet& b2) { return BitSet(b1)|=b2; }

inline BitSet::iterator BitSet::begin() const { return iterator(*this); }
inline BitSet::iterator BitSet::begin() const { assert(initialized()); return iterator(*this); }

inline BitSet::iterator BitSet::end() const { return iterator(*this,false); }
inline BitSet::iterator BitSet::end() const { assert(initialized()); return iterator(*this,false); }

inline BitSet::iterator::iterator(const BitSet& b, bool min) : b(&b), el(min && !b.empty()? b.min():INT_MIN) { }
inline BitSet::iterator::iterator(const BitSet& b, bool min) : b(&b), el(min && !b.empty()? b.min():INT_MIN) { assert(initialized()); }

inline BitSet::iterator& BitSet::iterator::operator++() {
assert(b->initialized());
if (el==b->max()) el=INT_MIN;
else el=b->next(el);
return *this;
}

inline BitSet::iterator BitSet::iterator::operator++(int) {
assert(b->initialized());
BitSet::iterator it(*this);
++(*this);
return it;
}

inline BitSet::iterator::operator int() const {
assert(b->initialized());
return el;
}

inline bool BitSet::initialized() const {
return bitset.table!=NULL;
}

} // end namespace ibex

#endif

0 comments on commit 850f804

Please sign in to comment.