void ofxSimpleGuiSliderBase<Type>::onKeyLeft() {
	if(!keyboardEdit)
		if (isShiftKeyDown()) {
			decrease(0.01);
		} else {
			decrease(0.001);
		}
}
Ejemplo n.º 2
0
void vsx_widget_2d_pager::event_mouse_down(vsx_widget_distance distance,vsx_widget_coords coords,int button)
{
  VSX_UNUSED(coords);
  VSX_UNUSED(button);

  distance.center.x > 0.0f ? increase() : decrease();
}
Ejemplo n.º 3
0
heapNode removeNode(int *heapSize, heapNode *heapArray){
	heapNode aux = heapArray[0];
	heapArray[0] = heapArray[*heapSize-1];
	(*heapSize)--;
	decrease(0, *heapSize, heapArray);
	return aux;
}
Ejemplo n.º 4
0
IndexedInstantiationInformation::~IndexedInstantiationInformation() {
  if(m_index && shouldDoDUChainReferenceCounting(this))
  {
    QMutexLocker lock(instantiationInformationRepository()->mutex());
    decrease(instantiationInformationRepository()->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
  }
}
Ejemplo n.º 5
0
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
	switch (id)
	{
		case BACKLIGHT_MODE1:
		showColor(69*bright/256,39*bright/256,160*bright/256); //4527A0
		break;
		case BACKLIGHT_MODE2:
		showColor(00*bright/256,204*bright/256,204*bright/256); //HOLO YOLO
		break;
		case BACKLIGHT_MODE3:
		showColor(255*bright/256,255*bright/256,255*bright/256);
		break;
		case BACKLIGHT_MODE4:
		showColor(rand()%255*bright/256,rand()%255*bright/256,rand()%255*bright/256);
		break;
		case BACKLIGHT_INCREASE:
		increase();
		showColor(mRed,mGreen,mBlue);
		break;
		case BACKLIGHT_DECREASE:
		decrease();
		showColor(mRed,mGreen,mBlue);
		break;
		case BACKLIGHT_OFF:
		showColor(0,0,0);
		break;
		default:
		showColor(0,0,0);
		break;
	}
}
bool DijkstraRouter::route()
{
    decrease();
    path = search();
    restore();
    return !path.empty() && pathCompliesPolicies(path);
}
Ejemplo n.º 7
0
   // precondition: num >= a 
   const count_digits count_digits::operator-=( const int64_t& aa )
   {
      int64_t a = aa;

      int64_t n = num;
      num      -= a;

      int nMod = (int) (n % base);
      int aMod = (int) (a % base);
      int aux;
      while( a > 1 )
      {
         cnt->remove( nMod );
         aux = nMod - aMod + base;
         cnt->add( aux % base );
         a /= base;

         if( aux < base ) ++a;

         aMod = (int) a % base;
         nMod = (int) ((n /= base) % base);
      }
      if( a == 1 )
         decrease( n );

      return *this;
   }
void ofxSimpleGuiSliderBase<Type>::onJoystick(float x, float y, int id){
	if(!keyboardEdit){
		if (x > 0) {
			increase(ofMap(x, 0, 1, 0, 0.1, true));
		} else if (x < 0){
			decrease(ofMap(x, 0, -1, 0, 0.1, true));
		}
	}
}
Ejemplo n.º 9
0
/**
 * Handles the mouse-wheels on the arrow-buttons.
 * @param action Pointer to an action.
 */
void SellState::lstItemsMousePress(Action *action)
{
	if (action->getAbsoluteXMouse() >= _lstItems->getArrowsLeftEdge() && action->getAbsoluteXMouse() <= _lstItems->getArrowsRightEdge())
	{
		_sel = _lstItems->getSelectedRow();
		if (action->getDetails()->button.button == SDL_BUTTON_WHEELUP) increase(_changeValueByMouseWheel);
		else if (action->getDetails()->button.button == SDL_BUTTON_WHEELDOWN) decrease(_changeValueByMouseWheel);
	}
}
Ejemplo n.º 10
0
Mytimer::Mytimer(QGraphicsItem *parent):QGraphicsTextItem(parent)
{
    //initialize
    time = 30;
    setPos(615,40);
    setPlainText(QString("time:")+QString::number(time)); // set time 30
    setDefaultTextColor(Qt::red);
    setFont(QFont("times",28 ));
    QTimer * timer = new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(decrease()));
    timer->start(1000);
}
Ejemplo n.º 11
0
void solve(vector<vector<int> > &res, vector<int> &num, int target, int skip_index) {
    int i = skip_index + 1;
    int j = num.size() - 1;

    vector<int> temp;

    while (i < j) {
        temp.clear();
        if (num[i] + num[j] == target) {
            temp.push_back(num[skip_index]);
            temp.push_back(num[i]);
            temp.push_back(num[j]);
            i = increase(num, i);
            j = decrease(num, j);
            res.push_back(temp);
        } else if (num[i] + num[j] < target) {
            i = increase(num, i);
        } else {
            j = decrease(num, j);
        }

    }
}
Ejemplo n.º 12
0
/*! Função auxiliar decrease. */
void decrease(int pos, int heapSize, heapNode *heapArray){
	heapNode aux;
	int decPos = 2*pos+1;
	if(2*pos+1 < heapSize){
		if((2*pos+2 < heapSize) && (heapArray[2*(pos)+2].weight < heapArray[2*(pos)+1].weight)) decPos++;
		if(heapArray[pos].weight > heapArray[decPos].weight){	
			aux = heapArray[pos];
			heapArray[pos] = heapArray[decPos];
			heapArray[decPos] = aux;
		
			decrease(decPos, heapSize, heapArray);
		}
	}
}
Ejemplo n.º 13
0
int32 Meter::increase(int32 n) {
	if (n < 0)
		return decrease(-n);

	int32 overflow = MAX<int32>(0, (_value + n) - _maxValue);

	int32 value = CLIP<int32>(_value + n, 0, _maxValue);
	if (_value == value)
		return overflow;

	_value = value;
	_needUpdate = true;

	return overflow;
}
Ejemplo n.º 14
0
IndexedInstantiationInformation& IndexedInstantiationInformation::operator=(const IndexedInstantiationInformation& rhs) {

  if(m_index && shouldDoDUChainReferenceCounting(this))
  {
    QMutexLocker lock(instantiationInformationRepository()->mutex());
    decrease(instantiationInformationRepository()->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
  }
  
  m_index = rhs.m_index;
  
  if(m_index && shouldDoDUChainReferenceCounting(this))
  {
    QMutexLocker lock(instantiationInformationRepository()->mutex());
    increase(instantiationInformationRepository()->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
  }
  return *this;
}
Ejemplo n.º 15
0
void DealDamageComponent::on_init() {
  auto body(get_user()->get_component<PhysicsBodyComponent>());
  if (body) {
    body->start_contact.connect([this](PhysicsBodyComponent* self, PhysicsBodyComponent* other, math::vec2 const&) {
      auto net_object(dynamic_cast<NetworkObject*>(other->get_user()));
      if (!net_object || net_object->is_local()) {
        auto life = other->get_user()->get_component<LifeComponent>();
        if (life) {
          life->decrease(Amount(), DamageSourceID(), self->get_linear_velocity()*0.5);
        }
      }

      return true;
    });
  } else {
    LOG_WARNING << "Failed to initialize DealDamageComponent: No PhysicsBodyComponent found!" << std::endl;
  }
}
Ejemplo n.º 16
0
void ArrayList::remove(int index)
{
	if(index >= 0 && index < mSize) {
		Object *target = mArray[index];
		target->release();
		if(index < mSize - 1) {
			int remain = mSize - 1 - index;
			Object** tmp = new Object*[remain];
			memset(tmp, 0, sizeof(Object*) * remain);
			memcpy(tmp, mArray + index + 1, sizeof(Object*) * remain);
			memcpy(mArray + index, tmp, sizeof(Object*) * remain);
			delete tmp;
		}
		mSize--;

		decrease();
	}
}
Ejemplo n.º 17
0
//!
//! \brief MainWindow::CreateActions
//!
void MainWindow::CreateActions()
{
    mActionExit = new QAction(tr("E&xit"), this);
    mActionExit->setStatusTip(tr("Exit the application"));
    QObject::connect(mActionExit, SIGNAL(triggered()), this, SLOT(close()));

    mActionIncrease = new QAction(tr("Increase"), this);
    mActionIncrease->setStatusTip(tr("Increase curve points"));
    QObject::connect(mActionIncrease, SIGNAL(triggered()), this, SLOT(increase()));

    mActionDecrease = new QAction(tr("Decrease"), this);
    mActionDecrease->setStatusTip(tr("Decrease curve points"));
    QObject::connect(mActionDecrease, SIGNAL(triggered()), this, SLOT(decrease()));

    mActionAnimate = new QAction(tr("Animate"), this);
    mActionAnimate->setStatusTip(tr("Animate events"));
    QObject::connect(mActionAnimate, SIGNAL(triggered()), this, SLOT(animate()));
}
Ejemplo n.º 18
0
//----------------------------------------------------------------------
box observer::SIVIA(box& X0,box& Psecours)	{
        int NbissectMax = N_Bissect_0;
	if (phase==0) NbissectMax=N_Bissect_0;
	if (phase==1) NbissectMax=N_Bissect_k;
	int Nbissect=0;
	Psecours = box(4);Psecours[1] = 5;Psecours[2] = 5;Psecours[3] = 0;Psecours[4] = 0;
	vector<box> Result;
	list<box> L;
	L.push_back(X0);
	box P;
	//Form1->R1.image->Refresh();
	while (!L.empty())	{
		P=L.front();
		//Form1->R1.DrawCadre(P,clBlue,psSolid,1,2,1);
		L.pop_front();
		bool sortie=false;
		while (!sortie)	{
			box Pold(P);
			Contract(P);
			if (P.IsEmpty()) sortie=true;
			if (decrease(Pold,P)<0.05) sortie=true;
		}
		if (!P.IsEmpty())	{
			if (Nbissect>NbissectMax)	{
				//Form1->R1.DrawBox(P,clRed,clRed,bsSolid,1,2);
				//Form1->R2.image->Refresh();
				Result.push_back(P);
			}
			else	{
				box P1,P2;
				Bisect(P,P1,P2);
                                Psecours=P;
				Nbissect++;
				L.push_back(P1);
				L.push_back(P2);
			}
		}
	}
	box R=Union(Result);
	//Form1->R1.DrawCadre(R,clGreen,psSolid,1,2,1);
	L.clear();

	return R;
}
Ejemplo n.º 19
0
void PickerWidget::create() {
  QVBoxLayout *layout = new QVBoxLayout;
  layout->setContentsMargins(0,0,0,0);
  layout->setSpacing(0);

  m_btnInc = new QPushButton("+");
  m_btnInc->setEnabled(false);
  layout->addWidget(m_btnInc);
  connect(m_btnInc, SIGNAL(clicked()), this, SLOT(increase()));

  m_label = new QLabel();
  m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  layout->addWidget(m_label);
  
  m_btnDec = new QPushButton("-");
  m_btnDec->setEnabled(false);
  layout->addWidget(m_btnDec);
  connect(m_btnDec, SIGNAL(clicked()), this, SLOT(decrease()));
  
  setLayout(layout);
}
Ejemplo n.º 20
0
void FlagStatus::Item::set(KeyCode key, Flags flags) {
  temporary_count_ = 0;

  // ------------------------------------------------------------
  if (key != flag_.getKeyCode()) return;

  // ------------------------------------------------------------
  if (flag_ == ModifierFlag::CAPSLOCK) {
    if (flags.isOn(flag_)) {
      lock_count_ = 1;
    } else {
      lock_count_ = 0;
    }

  } else {
    if (flags.isOn(flag_)) {
      increase();
    } else {
      decrease();
    }
  }
}
Ejemplo n.º 21
0
TimeUnitBox::TimeUnitBox(QWidget *parent, bool daysonly )
    : QWidget( parent ) {

    QVBoxLayout *vlay = new QVBoxLayout(this);
    vlay->setMargin(0);
    vlay->setSpacing(0);

    UpButton = new QPushButton( QPixmap(up_arrow), "", this );
    UpButton->setMaximumWidth( 26 );
    UpButton->setMaximumHeight( 13 );
    DownButton = new QPushButton( QPixmap(down_arrow), "", this );
    DownButton->setMaximumWidth( 26 );
    DownButton->setMaximumHeight( 13 );

    vlay->addWidget( UpButton );
    vlay->addWidget( DownButton );
    //	setLayout( vlay );

    setDaysOnly( daysonly );

    connect( UpButton, SIGNAL( clicked() ), this, SLOT( increase() ) );
    connect( DownButton, SIGNAL( clicked() ), this, SLOT( decrease() ) );
}
Ejemplo n.º 22
0
 void decrease(ModifierFlag flag) { decrease(Flags(flag)); }
Ejemplo n.º 23
0
 void remove(Value newValue, bool isDecision = false) {if (newValue==inf) increase(newValue+1, isDecision); else if (newValue==sup) decrease(newValue-1, isDecision);}
Ejemplo n.º 24
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_mapping_minimum, Tp, int2_sets )
{
  {
    Tp fix(100, randomize(-20, 20));
    // Prove that you can find the min value with N nodes, down to 1 nodes
    while (!fix.container.empty())
      {
        unsigned int count = 0;
        int min_value_0 = (*fix.container.begin())[0];
        int min_value_1 = (*fix.container.begin())[1];
        for(typename Tp::container_type::iterator
              i = fix.container.begin(); i != fix.container.end(); ++i)
          {
            int tmp = (*i)[0];
            if (tmp < min_value_0) { min_value_0 = tmp; }
            tmp = (*i)[1];
            if (tmp < min_value_1) { min_value_1 = tmp; }
            ++count;
          }
        BOOST_CHECK_EQUAL(count, fix.container.size());
        mapping_iterator<typename Tp::container_type> iter;
        dimension_type mapping_dim = 0;
        iter = mapping_begin(fix.container, mapping_dim);
        BOOST_CHECK_EQUAL((*iter)[mapping_dim], min_value_0);
        mapping_dim = 1;
        iter = mapping_begin(fix.container, mapping_dim);
        BOOST_CHECK_EQUAL((*iter)[mapping_dim], min_value_1);
        fix.container.erase(iter);
      }
  }
  { // A tree where all elements are the same!
    Tp fix(100, same());
    // Prove that you can find the min value with N nodes, down to 1 nodes
    while (!fix.container.empty())
      {
        unsigned int count = 0;
        for(typename Tp::container_type::iterator
              i = fix.container.begin(); i != fix.container.end(); ++i)
          { ++count; }
        BOOST_CHECK_EQUAL(count, fix.container.size());
        mapping_iterator<typename Tp::container_type> iter;
        iter = mapping_begin(fix.container, 0);
        BOOST_CHECK_EQUAL((*iter)[0], 100);
        iter = mapping_begin(fix.container, 1);
        BOOST_CHECK_EQUAL((*iter)[1], 100);
        fix.container.erase(iter);
      }
  }
  { // test at the limit: a tree with 1 element
    Tp fix(1, same());
    mapping_iterator<const typename Tp::container_type> iter;
    iter = mapping_cbegin(fix.container, 0);
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
    iter = mapping_cbegin(fix.container, 1);
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
  }
  { // test at the limit: an unbalanced tree (i.e. insertions in order)!
    Tp fix(100, decrease());
    mapping_iterator<typename Tp::container_type> iter;
    dimension_type mapping_dim = 0;
    iter = mapping_begin(fix.container, mapping_dim);
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
  }
  { // test at the limit: an unbalanced tree (i.e insertions in order)!
    Tp fix(100, increase());
    mapping_iterator<typename Tp::container_type> iter;
    dimension_type mapping_dim = 1;
    iter = mapping_begin(fix.container, mapping_dim);
    BOOST_CHECK_EQUAL((*iter)[0], 0); // should be (0, 0);
    BOOST_CHECK_EQUAL((*iter)[1], 0);
  }
}
Ejemplo n.º 25
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_mapping_upper_bound, Tp, quad_maps )
{
  { // find the smallest element that is greater than key
    Tp fix(100, randomize(-2, 2));
    quad lower (-3, -3, -3, -3);
    quad in (-1, -1, -1, -1);
    quad upper (1, 1, 1, 1);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, in));
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim)
                    || quad_less()(mapping_dim, in, iter->first));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim)
                    || !quad_less()(mapping_dim, (--iter)->first, in));
        iter = mapping_upper_bound(fix.container, mapping_dim, lower);
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
  { // same test with a tree filled with similar values
    Tp fix(100, same());
    quad lower (99, 99, 99, 99);
    quad in (100, 100, 100, 100);
    quad upper (101, 101, 101, 101);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
  { // test at the limit: tree with 1 value
    Tp fix(1, same());
    quad lower (0, 0, 0, 0);
    quad in (1, 1, 1, 1);
    quad upper (2, 2, 2, 2);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<const typename Tp::container_type>
          iter (mapping_cupper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_cbegin(fix.container, mapping_dim));
        iter = mapping_cupper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter == mapping_cend(fix.container, mapping_dim));
        iter = mapping_cupper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_cend(fix.container, mapping_dim));
      }
  }
  { // test at the limit: tree filled with decreasing values
    Tp fix(100, decrease()); // first (100, 100, 100, 100), last (1, 1, 1, 1)
    quad lower(0, 0, 0, 0);
    quad in (99, 99, 99, 99);
    quad upper(100, 100, 100, 100);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter != mapping_end(fix.container, mapping_dim)
                    && ++iter == mapping_end(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
  { // test at the limit: tree filled with increasing values
    Tp fix(100, increase()); // first (0, 0, 0, 0), last (99, 99, 99, 99)
    quad lower(-1, -1, -1, -1);
    quad in(98, 98, 98, 98);
    quad upper (99, 99, 99, 99);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter != mapping_end(fix.container, mapping_dim)
                    && ++iter == mapping_end(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
}
Ejemplo n.º 26
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_mapping_decrement, Tp, int2_maps )
{
  { // test the invarient of the increment
    Tp fix(100, randomize(-3, 3));
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        double tmp = iter->first[mapping_dim];
        for (; iter != end; ++iter)
          {
            BOOST_CHECK_GE(tmp, iter->first[mapping_dim]);
            tmp = iter->first[mapping_dim];
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
  { // test at the limit: a tree where all elements are the same
    Tp fix(100, same());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        for (; iter != end; ++iter)
          {
            BOOST_CHECK_EQUAL(100, iter->first[mapping_dim]);
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
  { // test at the limit: a tree with 2 elements
    Tp fix(2, same());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        mapping_iterator<const typename Tp::container_type>
          pre = mapping_cend(fix.container, mapping_dim),
          post = mapping_cend(fix.container, mapping_dim),
          begin = mapping_cbegin(fix.container, mapping_dim);
        BOOST_CHECK(pre != begin);
        BOOST_CHECK(--pre != post--);
        BOOST_CHECK(pre == post);
        BOOST_CHECK(post-- != begin);
        BOOST_CHECK(--pre == begin);
        BOOST_CHECK(post == begin);
      }
  }
  { // test at the limit: a right-unbalanced tree (pre-increment)
    Tp fix(100, increase());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        double tmp = iter->first[mapping_dim];
        for (; iter != end; ++iter)
          {
            BOOST_CHECK_GE(tmp, iter->first[mapping_dim]);
            tmp = iter->first[mapping_dim];
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
  { // test at the limit: a left-unbalanced tree (post-increment)
    Tp fix(100, decrease());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        double tmp = iter->first[mapping_dim];
        for (; iter != end; iter++)
          {
            BOOST_CHECK_GE(tmp, iter->first[mapping_dim]);
            tmp = iter->first[mapping_dim];
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
}
Ejemplo n.º 27
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_mapping_maximum, Tp, int2_sets )
{
  {
    Tp fix(100, randomize(-20, 20));
    // Prove that you can find the max value with N nodes, down to 1 nodes
    while (!fix.container.empty())
      {
        unsigned int count = 0;
        int max_value_0 = (*fix.container.begin())[0];
        int max_value_1 = (*fix.container.begin())[1];
        for(typename Tp::container_type::iterator
              i = fix.container.begin(); i != fix.container.end(); ++i)
          {
            int tmp = (*i)[0];
            if (tmp > max_value_0) { max_value_0 = tmp; }
            tmp = (*i)[1];
            if (tmp > max_value_1) { max_value_1 = tmp; }
            ++count;
          }
        BOOST_CHECK_EQUAL(count, fix.container.size());
        mapping_iterator<typename Tp::container_type> iter;
        iter = mapping_end(fix.container, 0);
        --iter; // When at the end, this call the 'maximum' function
        BOOST_REQUIRE_EQUAL((*iter)[0], max_value_0);
        iter = mapping_end(fix.container, 1); --iter;
        BOOST_REQUIRE_EQUAL((*iter)[1], max_value_1);
        fix.container.erase(iter);
      }
  }
  { // A tree where all elements are the same!
    Tp fix(100, same());
    // Prove that you can find the max value with N nodes, down to 1 nodes
    while (!fix.container.empty())
      {
        unsigned int count = 0;
        for(typename Tp::container_type::iterator
              i = fix.container.begin(); i != fix.container.end(); ++i)
          { ++count; }
        BOOST_CHECK_EQUAL(count, fix.container.size());
        mapping_iterator<typename Tp::container_type> iter;
        iter = mapping_end(fix.container, 0); --iter;
        BOOST_CHECK_EQUAL((*iter)[0], 100);
        iter = mapping_end(fix.container, 1); --iter;
        BOOST_CHECK_EQUAL((*iter)[1], 100);
        fix.container.erase(iter);
      }
  }
  { // test at the limit: a tree with 1 element
    Tp fix(1, same());
    mapping_iterator<const typename Tp::container_type> iter;
    iter = mapping_cend(fix.container, 0); --iter;
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
    iter = mapping_cend(fix.container, 1); --iter;
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
  }
  { // test at the limit: an unbalanced tree!
    Tp fix(100, decrease());
    mapping_iterator<typename Tp::container_type> iter;
    iter = mapping_end(fix.container, 0); --iter;
    BOOST_CHECK_EQUAL((*iter)[0], 100); // should be (100, 100);
    BOOST_CHECK_EQUAL((*iter)[1], 100);
  }
  { // test at the limit: an unbalanced tree!
    Tp fix(100, increase());
    mapping_iterator<typename Tp::container_type> iter;
    iter = mapping_end(fix.container, 1); --iter;
    BOOST_CHECK_EQUAL((*iter)[0], 99); // should be (99, 99);
    BOOST_CHECK_EQUAL((*iter)[1], 99);
  }
}
Ejemplo n.º 28
0
BigInteger Solver::binaryChoicePointSBTD(Cluster* cluster, int varIndex, Value value)
{
    if (ToulBar2::interrupted)
        throw TimeOut();
    Cost cub = 1;
    Cost lbgood = 0;
    BigInteger nbSol = 0, nb = 0;
    assert(wcsp->unassigned(varIndex));
    assert(wcsp->canbe(varIndex, value));
    bool dichotomic = (ToulBar2::dichotomicBranching && ToulBar2::dichotomicBranchingSize < wcsp->getDomainSize(varIndex));
    Value middle = value;
    bool increasing = true;
    if (dichotomic) {
        middle = (wcsp->getInf(varIndex) + wcsp->getSup(varIndex)) / 2;
        if (value <= middle)
            increasing = true;
        else
            increasing = false;
    }
    try {
        Store::store();
        assert(wcsp->getTreeDec()->getCurrentCluster() == cluster);

        wcsp->setUb(cub);
        if (CUT(lbgood, cub))
            THROWCONTRADICTION;
        lastConflictVar = varIndex;
        if (dichotomic) {
            if (increasing)
                decrease(varIndex, middle);
            else
                increase(varIndex, middle + 1);
        } else
            assign(varIndex, value);
        lastConflictVar = -1;
        nb = sharpBTD(cluster);
        nbSol += nb;
    } catch (Contradiction) {
        wcsp->whenContradiction();
    }
    Store::restore();
    nbBacktracks++;
    if (ToulBar2::restart > 0 && nbBacktracks > nbBacktracksLimit)
        throw NbBacktracksOut();
#ifdef OPENMPI
    if (ToulBar2::vnsParallel && ((nbBacktracks % 128) == 0) && MPI_interrupted())
        throw TimeOut();
#endif
    try {
        Store::store();
        assert(wcsp->getTreeDec()->getCurrentCluster() == cluster);
        //		assert(wcsp->getLb() == cluster->getLbRec());
        wcsp->setUb(cub);
        if (CUT(lbgood, cub))
            THROWCONTRADICTION;
        if (dichotomic) {
            if (increasing)
                increase(varIndex, middle + 1);
            else
                decrease(varIndex, middle);
        } else
            remove(varIndex, value);

        nb = sharpBTD(cluster);
        nbSol += nb;
    } catch (Contradiction) {
        wcsp->whenContradiction();
    }
    Store::restore();
    return nbSol;
}
Ejemplo n.º 29
0
void
menu_keys ()
{
  static int      enter;
  int             ent = 0;
  static int	  esc;
#ifdef MOUSE
  static int      button;
  int             but = 0;
#endif
  if (maxim[1].max != maxlevel && !client)
    main_menu ();
  changed = 0;
  if (IsPressedLeft ())
    {
      int             i;
      for (i = 0; i < nnumbers; i++)
	if (maxim[i].line == selected)
	  decrease (i);
    }
  if (IsPressedRight ())
    {
      int             i;
      for (i = 0; i < nnumbers; i++)
	if (maxim[i].line == selected)
	  increase (i);
    }
#ifdef MOUSE
  but = nomouse ? 0 : MouseButtons ();
  if (but)
    {
      int             i;
      for (i = 0; i < nnumbers; i++)
	{
	  if (MouseX () > maxim[i].x &&
	      MouseX () < maxim[i].x + 8 &&
	      MouseY () > maxim[i].y &&
	      MouseY () < maxim[i].y + 8)
	    increase (i);
	  if (MouseX () > minim[i].x &&
	      MouseX () < minim[i].x + 8 &&
	      MouseY () > minim[i].y &&
	      MouseY () < minim[i].y + 8)
	    decrease (i);
	}
    }
  if (!but && button)
    {
      int             i;
      i = (MouseY () - MAPHEIGHT / 2 - 20 + 5 * nmenu) / 10;
      if (i >= 0 && i < nmenu)
	{
	  selected = i;
#ifdef SOUND
	  if (ssound)
	    play_sound (S_CREATOR2);
#endif
	  menu[selected].func ();
	  button = 0;
	  return;
	}
    }
  button = but;
#endif
  if (IsPressedEsc ())
    {
      if(!esc) {
      if (client || nnumbers == 2)
	quit ();
      to_main_menu ();
      }
      esc=1;
    } else esc=0;
  if (IsPressedUp () && !mtime && selected > 0)
    selected--, fit_selector ();
  if (IsPressedDown () && !mtime && selected < nmenu - 1)
    selected++, fit_selector ();
  if (IsPressedEnter () && !mtime)
    ent = 1;
  if (!ent && enter)
    {
#ifdef SOUND
      if (ssound)
	play_sound (S_CREATOR2);
#endif
      menu[selected].func ();
    }
  enter = ent;
  if (!changed)
    inctime = 7, waittime = 0;

}
Ejemplo n.º 30
0
 static void decrease(PointingButton button) { decrease(Buttons(button)); }