Ejemplo n.º 1
0
void LatexPreviewWindow::SetImage(const wxBitmap& img)
{
    Freeze();

    int old_width = 0,
        old_height = 0;
    if (m_img.IsOk()) {
        old_width = m_img.GetWidth();
        old_height = m_img.GetHeight();
    }

    wxSize increase(img.GetWidth() - old_width,
                    img.GetHeight() - old_height),
           frame_size( GetSize() ),
           new_img_size(img.GetWidth() + 40, img.GetHeight() + 40);
    m_img = img;

    // m_mainpanel->Layout();

    // m_control_image->SetVirtualSizeHints( new_img_size );
    m_control_image->SetInitialSize( new_img_size );
    m_control_image->SetMinSize( new_img_size );
    m_control_image->SetSize( new_img_size );

    m_panel_formula->GetSizer()->Layout();
    GetSizer()->SetSizeHints(this);

    if (m_resize_frame) {
        if (m_control_image->GetSize().x > m_panel_image->GetSize().x)
            frame_size.x += m_control_image->GetSize().x - m_panel_image->GetSize().x;
        frame_size.y += increase.y;
    }

    // m_control_image->Refresh();
    // m_control_image->Update();
    // m_mainpanel->GetSizer()->SetSizeHints(m_mainpanel);

    SetSize(frame_size);
    Thaw();

    Refresh();
}
/*
 * fun introot n =
 * if n = 0
 *    then 0
 * else increase (2 * introot (n div 4), n)
 */
void
introot (mpz_t r, const mpz_t n)
{
  unsigned long int i = 0;
  unsigned long int size = mpz_sizeinbase (n, 4);
  mpz_t *stack = malloc (size * sizeof (mpz_t));

  mpz_set (r, n);
  for (i = 1; i <= size; i++)
    {
      mpz_init_set (*(stack + size - i), r);
      mpz_fdiv_q_ui (r, r, 4);
    }
  for (i = 0; i < size; i++)
    {
      mpz_mul_ui (r, r, 2);
      increase (r, *(stack + i));
      mpz_clear (*(stack + i));
    }
  free (stack);
}
Ejemplo n.º 3
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.º 4
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.º 5
0
			V get(K key)
			{
				if(prelude_unlikely(!T::valid_key(key)))
					return 0;

				size_t hash = T::hash_key(key);
				size_t index = hash & mask;
				V entry = table[index];
				V tail = entry;

				while(T::valid_value(entry))
				{
					T::verify_value(entry);

					if(T::compare_key_value(key, hash, entry))
						return entry;

					tail = entry;
					entry = T::get_value_next(entry);
				}

				if(T::create_value())
				{
					V value = T::create_value(get_allocator(), key, hash);

					if(tail)
						T::set_value_next(tail, value);
					else
						table[index] = value;

					T::set_value_next(value, T::invalid_value());

					increase();

					return value;
				}
				else
					return T::invalid_value();
			}
Ejemplo n.º 6
0
 int candy(vector<int>& ratings) {
     int n = ratings.size();
     if(n<2)
         return 1;
     vector<int> increase(n,0);
     for(int i = 1,inc = 1; i<ratings.size();i++)
     {
         if(ratings[i]>ratings[i-1])
             increase[i] = max(inc++,increase[i]);
         else
             inc = 1;
     }
     
     for(int k = ratings.size()-2,inc = 1; k>-1;k--)
     {
         if(ratings[k]>ratings[k+1])
             increase[k] = max(inc++,increase[k]);
         else
             inc = 1;
     }
     return accumulate(&increase[0],&increase[0]+n,n);
 }
Ejemplo n.º 7
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.º 8
0
			V get(K key)
			{
				if(!T::valid_key(key))
					return 0;

				size_t index = T::hash_key(key) & mask;
				V entry = table[index];
				V tail = entry;
				
				while(T::valid_value(entry))
				{
					if(T::compare_key_value(key, entry))
						return entry;
						
					tail = entry;
					entry = T::get_value_next(entry);
				}

				if(T::create_value())
				{
					V value = T::create_value(key, memory_pool);

					if(tail)
						T::set_value_next(tail, value);
					else
						table[index] = value;

					T::set_value_next(value, T::invalid_value());
					
					increase();

					return value;
				}
				else
					return 0;
			}
Ejemplo n.º 9
0
int main(){
	insert(5);
	insert(7);
	insert(3);
	insert(8);
	insert(12);
	insert(14);
	insert(118);
	print_queue();
	
	printf("\nextractMax:\n");
	int max = extractMax();		
	printf("\nThe Max is %d.\n",max);
	print_queue();
	
	printf("\nincrease, index is [5] and value is [10]:\n");
	increase(5,10);
	print_queue();
	
	printf("\nChange value, index is [5] and value is [10]:\n");
	change(5,10);
	print_queue();
	return 0;
}
Ejemplo n.º 10
0
void ArrayList::add(int index, Object *obj)
{
	if(obj == NULL) {
		return ;
	}
	if(index < 0 || index > mSize) {
		return ;
	}
	increase();
	obj->retain();
	Object** tmp = NULL;
	int remain = mSize - index;
	if(remain > 0) {
		tmp = new Object*[remain];
		memset(tmp, 0, sizeof(Object*) * remain);
		memcpy(tmp, mArray + index, sizeof(Object*) * remain);
	}
	mArray[index] = obj;
	if(remain > 0) {
		memcpy(mArray + index + 1, tmp, sizeof(Object*) * remain);
		delete tmp;
	}
	mSize++;
}
Ejemplo n.º 11
0
void   testVector(int testSize) {
   printf("\n  ==== Test %2d. Generate a random vector\n", testID++);
   Vector<T> V;
   for (int i = 0; i < testSize; i++) V.insert(dice((Rank)i+1), dice((T)testSize*3)); //在[0, 3n)中选择n个数,随机插入向量
   PRINT(V);
   permute(V);
   PRINT(V)

   printf("\n  ==== Test %2d. Lowpass on\n", testID++); PRINT(V);
   int i = V.size(); while (0 < --i) { V[i-1] += V[i]; V[i-1] >>= 1; }    PRINT(V);

   printf("\n  ==== Test %2d. Increase\n", testID++); PRINT(V);
   increase(V); PRINT(V);

   printf("\n  ==== Test %2d. FIND in\n", testID++); PRINT(V);
   TestFind<T>(V, testSize);

   printf("\n  ==== Test %2d. Sort degenerate intervals each of size 1 in\n", testID++, 0, V.size()); PRINT(V);
   for (int i = 0; i < V.size(); i += V.size()/5) { V.sort(i, i); PRINT(V); } //element by element

   printf("\n  ==== Test %2d. Sort 5 intervals each of size %d in\n", testID++, V.size()/5); PRINT(V);
   for (int i = 0; i < V.size(); i += V.size()/5) { V.sort(i, min(V.size(), i+V.size()/5)); PRINT(V); } //interval by interval

   printf("\n  ==== Test %2d. Sort the entire vector of\n", testID++, 0, V.size()); PRINT(V);
   V.sort();   PRINT(V);

   printf("\n  ==== Test %2d. FIND in\n", testID++); PRINT(V);
   TestFind<T>(V, testSize);

   printf("\n  ==== Test %2d. SEARCH in\n", testID++); PRINT(V);
   TestSearch<T>(V);

   printf("\n  ==== Test %2d. Unsort interval [%d, %d) in\n", testID++, V.size()/4, 3*V.size()/4); PRINT(V);
   V.unsort(V.size()/4, 3*V.size()/4);   PRINT(V);

   printf("\n  ==== Test %2d. Unsort interval [%d, %d) in\n", testID++, 0, V.size()); PRINT(V);
   V.unsort();   PRINT(V);

   printf("\n  ==== Test %2d. Copy interval [%d, %d) from\n", testID++, V.size()/4, 3*V.size()/4); PRINT(V);
   Vector<T> U(V, V.size()/4, 3*V.size()/4);
   PRINT(U);

   printf("\n  ==== Test %2d. Copy from\n", testID++); PRINT(V);
   Vector<T> W(V);
   PRINT(W);

   printf("\n  ==== Test %2d. Clone from\n", testID++); PRINT(U);
   W = U;
   PRINT(W);

   printf("\n  ==== Test %2d. Remove redundancy in unsorted\n", testID++); PRINT(V);
   printf("%d node(s) removed\n", V.deduplicate());   PRINT(V);

   printf("\n  ==== Test %2d. Sort interval [%d, %d) in\n", testID++, 0, V.size()); PRINT(V);
   V.sort();   PRINT(V);

   printf("\n  ==== Test %2d. FIND in V[%d]\n", testID++); PRINT(V);
   TestFind<T>(V, testSize);

   printf("\n  ==== Test %2d. SEARCH & INSERT in\n", testID++); PRINT(V);
   TestOrderedInsertion<T>(V, testSize);  PRINT(V);

   printf("\n  ==== Test %2d. Remove redundancy in sorted\n", testID++); PRINT(V);
   printf("%d node(s) removed\n", V.uniquify());   PRINT(V);
}
Ejemplo n.º 12
0
 static void increase(PointingButton button) { increase(Buttons(button)); }
Ejemplo n.º 13
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_neighbor_upper_bound, Tp, quad_sets )
{
  typedef quadrance<typename Tp::container_type, int, quad_diff> metric_type;
  typedef typename metric_type::distance_type distance_type;
  typedef neighbor_iterator<typename Tp::container_type, metric_type>
    neighbor_iterator_type;
  // Prove that you can find lower bound with N nodes, down to 1 node
  {
    Tp fix(100, randomize(-20, 20));
    metric_type metric;
    quad target;
    while (!fix.container.empty())
      {
        randomize(-22, 22)(target, 0, 0);
        // Find min and max dist first
        distance_type min_dist;
        distance_type max_dist;
        typename Tp::container_type::iterator it = fix.container.begin();
        min_dist = max_dist
          = metric.distance_to_key(fix.container.rank()(), *it, target);
        ++it;
        for (; it != fix.container.end(); ++it)
          {
            distance_type tmp
              = metric.distance_to_key(fix.container.rank()(), *it, target);
            if (tmp < min_dist) min_dist = tmp;
            if (tmp > max_dist) max_dist = tmp;
          }
        distance_type avg_dist = (min_dist + max_dist) / 2;
        // use this knowledge to test the upper bound
        neighbor_iterator_type i
          = neighbor_upper_bound(fix.container, metric, target, min_dist);
        BOOST_CHECK(i != neighbor_begin(fix.container, metric, target));
        if (i != neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_LT(min_dist, distance(i)); }
        BOOST_CHECK_EQUAL(min_dist, distance(--i));
        i = neighbor_upper_bound(fix.container, metric, target, max_dist);
        BOOST_CHECK(i == neighbor_end(fix.container, metric, target));
        i = neighbor_upper_bound(fix.container, metric, target, avg_dist);
        if (i != neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_GT(distance(i), avg_dist); }
        if (i == neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_LE(distance(--i), avg_dist); }
        fix.container.erase(i);
      }
  }
  // Prove that you can find the upper bound when node and target are same
  {
    Tp fix(100, same());
    metric_type metric;
    quad target;
    same()(target, 0, 100);
    // All points and targets are the same.
    while (!fix.container.empty())
      {
        neighbor_iterator_type i
          = neighbor_upper_bound(fix.container, metric, target, 1);
        BOOST_CHECK(i == neighbor_end(fix.container, metric, target));
        i = neighbor_upper_bound(fix.container, metric, target, 0);
        BOOST_CHECK(i == neighbor_end(fix.container, metric, target));
        fix.container.erase(--i);
      }
  }
  // Prove that you can find the upper bound in an unbalanced tree
  {
    Tp fix(100, increase());
    metric_type metric;
    quad target;
    while (!fix.container.empty())
      {
        randomize(0, 100)(target, 0, 0);
        // Find min and max dist first
        distance_type min_dist;
        distance_type max_dist;
        typename Tp::container_type::iterator it = fix.container.begin();
        min_dist = max_dist
          = metric.distance_to_key(fix.container.rank()(), *it, target);
        ++it;
        for (; it != fix.container.end(); ++it)
          {
            distance_type tmp
              = metric.distance_to_key(fix.container.rank()(), *it, target);
            if (tmp < min_dist) min_dist = tmp;
            if (tmp > max_dist) max_dist = tmp;
          }
        distance_type avg_dist = (min_dist + max_dist) / 2;
        // Use this knowledge to test the upper bound
        neighbor_iterator_type i
          = neighbor_upper_bound(fix.container, metric, target, min_dist);
        BOOST_CHECK(i != neighbor_begin(fix.container, metric, target));
        if (i != neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_LT(min_dist, distance(i)); }
        BOOST_CHECK_EQUAL(min_dist, distance(--i));
        i = neighbor_upper_bound(fix.container, metric, target, max_dist);
        BOOST_CHECK(i == neighbor_end(fix.container, metric, target));
        i = neighbor_upper_bound(fix.container, metric, target, avg_dist);
        if (i != neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_GT(distance(i), avg_dist); }
        if (i == neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_LE(distance(--i), avg_dist); }
        fix.container.erase(i);
      }
  }
  // Prove that you can find the upper bound in an unbalanced tree
  {
    Tp fix(100, decrease());
    metric_type metric;
    quad target;
    while (!fix.container.empty())
      {
        randomize(0, 100)(target, 0, 0);
        // Find min and max dist first
        distance_type min_dist;
        distance_type max_dist;
        typename Tp::container_type::iterator it = fix.container.begin();
        min_dist = max_dist
          = metric.distance_to_key(fix.container.rank()(), *it, target);
        ++it;
        for (; it != fix.container.end(); ++it)
          {
            distance_type tmp
              = metric.distance_to_key(fix.container.rank()(), *it, target);
            if (tmp < min_dist) min_dist = tmp;
            if (tmp > max_dist) max_dist = tmp;
          }
        distance_type avg_dist = (min_dist + max_dist) / 2;
        // Use this knowledge to test the upper bound
        neighbor_iterator_type i
          = neighbor_upper_bound(fix.container, metric, target, min_dist);
        BOOST_CHECK(i != neighbor_begin(fix.container, metric, target));
        if (i != neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_LT(min_dist, distance(i)); }
        BOOST_CHECK_EQUAL(min_dist, distance(--i));
        i = neighbor_upper_bound(fix.container, metric, target, max_dist);
        BOOST_CHECK(i == neighbor_end(fix.container, metric, target));
        i = neighbor_upper_bound(fix.container, metric, target, avg_dist);
        if (i != neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_GT(distance(i), avg_dist); }
        if (i == neighbor_end(fix.container, metric, target))
          { BOOST_CHECK_LE(distance(--i), avg_dist); }
        fix.container.erase(i);
      }
  }
}
Ejemplo n.º 14
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.º 15
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.º 16
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.º 17
0
pair<Cost, Cost> Solver::binaryChoicePoint(Cluster* cluster, Cost lbgood, Cost cub, int varIndex, Value value)
{
    assert(lbgood < cub);
    if (ToulBar2::interrupted)
        throw TimeOut();
    Cost clb = cub;
    TreeDecomposition* td = wcsp->getTreeDec();
    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(td->getCurrentCluster() == cluster);
        assert(wcsp->getLb() == cluster->getLbRec());
        wcsp->setUb(cub);
        Cost bestlb = lbgood;
        if (CUT(bestlb, cub))
            THROWCONTRADICTION;
        if (ToulBar2::btdMode >= 2) {
            Cost rds = td->getLbRecRDS();
            bestlb = MAX(bestlb, rds);
            if (CUT(bestlb, cub))
                THROWCONTRADICTION;
        }
        lastConflictVar = varIndex;
        if (dichotomic) {
            if (increasing)
                decrease(varIndex, middle);
            else
                increase(varIndex, middle + 1);
        } else
            assign(varIndex, value);
        lastConflictVar = -1;
        bestlb = MAX(bestlb, wcsp->getLb());
        pair<Cost, Cost> res = recursiveSolve(cluster, bestlb, cub);
        clb = MIN(res.first, clb);
        cub = MIN(res.second, cub);
    } 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
    cluster->nbBacktracks++;
    try {
        Store::store();
        assert(wcsp->getTreeDec()->getCurrentCluster() == cluster);
        assert(wcsp->getLb() == cluster->getLbRec());
        wcsp->setUb(cub);
        Cost bestlb = lbgood;
        if (CUT(bestlb, cub))
            THROWCONTRADICTION;
        if (ToulBar2::btdMode >= 2) {
            Cost rds = td->getLbRecRDS();
            bestlb = MAX(bestlb, rds);
            if (CUT(bestlb, cub))
                THROWCONTRADICTION;
        }
        if (dichotomic) {
            if (increasing)
                increase(varIndex, middle + 1, cluster->nbBacktracks >= cluster->hbfsLimit || nbBacktracks >= cluster->hbfsGlobalLimit);
            else
                decrease(varIndex, middle, cluster->nbBacktracks >= cluster->hbfsLimit || nbBacktracks >= cluster->hbfsGlobalLimit);
        } else
            remove(varIndex, value, cluster->nbBacktracks >= cluster->hbfsLimit || nbBacktracks >= cluster->hbfsGlobalLimit);
        bestlb = MAX(bestlb, wcsp->getLb());
        if (!ToulBar2::hbfs && cluster == td->getRoot() && initialDepth + 1 == Store::getDepth()) {
            initialDepth++;
            showGap(bestlb, cub);
        };
        if (cluster->nbBacktracks >= cluster->hbfsLimit || nbBacktracks >= cluster->hbfsGlobalLimit) {
            addOpenNode(*(cluster->cp), *(cluster->open), bestlb, cluster->getCurrentDelta());
        } else {
            pair<Cost, Cost> res = recursiveSolve(cluster, bestlb, cub);
            clb = MIN(res.first, clb);
            cub = MIN(res.second, cub);
        }
    } catch (Contradiction) {
        wcsp->whenContradiction();
    }
    Store::restore();
    assert(lbgood <= clb);
    assert(clb <= cub);
    return make_pair(clb, cub);
}
Ejemplo n.º 18
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_neighbor_decrement, Tp, int2_maps )
{
  // Prove that you can iterate N nodes, down to 1 node
  {
    Tp fix(100, randomize(-20, 20));
    int2 target;
    typedef typename neighbor_iterator<typename Tp::container_type>
      ::distance_type distance_type;
    while (!fix.container.empty())
      {
        randomize(-22, 22)(target, 0, 0);
        size_t countdown = fix.container.size();
        std::reverse_iterator<neighbor_iterator<typename Tp::container_type> >
          iter(--neighbor_end(fix.container, target)),
          end(neighbor_begin(fix.container, target));
        distance_type max_dist = distance(iter.base());
        for(; --countdown != 0 && iter != end; ++iter)
          {
            distance_type tmp = distance(iter.base());
            BOOST_CHECK_LE(tmp, max_dist);
            max_dist = tmp;
          }
        BOOST_CHECK_EQUAL(countdown, 0u);
        BOOST_CHECK(iter == end);
        fix.container.erase(fix.container.begin());
      }
  }
  // Prove that you can iterate a very unbalanced tree
  {
    Tp fix(40, increase());
    int2 target;
    typedef typename neighbor_iterator<typename Tp::container_type>
      ::distance_type distance_type;
    while (!fix.container.empty())
      {
        randomize(0, 40)(target, 0, 0);
        size_t countdown = fix.container.size();
        std::reverse_iterator<neighbor_iterator<typename Tp::container_type> >
          iter(--neighbor_end(fix.container, target)),
          end(neighbor_begin(fix.container, target));
        distance_type max_dist = distance(iter.base());
        for(; --countdown != 0 && iter != end; ++iter)
          {
            distance_type tmp = distance(iter.base());
            BOOST_CHECK_LE(tmp, max_dist);
            max_dist = tmp;
          }
        BOOST_CHECK_EQUAL(countdown, 0u);
        BOOST_CHECK(iter == end);
        fix.container.erase(fix.container.begin());
      }
  }
  // Prove that you can iterate an opposite unbalanced tree
  {
    Tp fix(40, decrease());
    int2 target;
    typedef typename neighbor_iterator<typename Tp::container_type>
      ::distance_type distance_type;
    while (!fix.container.empty())
      {
        randomize(0, 40)(target, 0, 0);
        size_t countdown = fix.container.size();
        std::reverse_iterator<neighbor_iterator<typename Tp::container_type> >
          iter(--neighbor_end(fix.container, target)),
          end(neighbor_begin(fix.container, target));
        distance_type max_dist = distance(iter.base());
        for(; --countdown != 0 && iter != end; ++iter)
          {
            distance_type tmp = distance(iter.base());
            BOOST_CHECK_LE(tmp, max_dist);
            max_dist = tmp;
          }
        BOOST_CHECK_EQUAL(countdown, 0u);
        BOOST_CHECK(iter == end);
        fix.container.erase(fix.container.begin());
      }
  }
  // Prove that you can iterate equivalent nodes
  {
    int2 target;
    same()(target, 0, 100);
    Tp fix(100, same());
    std::reverse_iterator<neighbor_iterator<typename Tp::container_type> >
      iter(neighbor_end(fix.container, target)),
      end(neighbor_begin(fix.container, target));
    size_t count = 1;
    ++iter;
    for(; iter != end && count < fix.container.size(); ++iter, ++count)
      {
        BOOST_CHECK_CLOSE(distance(iter.base()), 0.0, 0.000000001);
      }
    BOOST_CHECK(iter == end);
    BOOST_CHECK_EQUAL(count, fix.container.size());
  }
}
Ejemplo n.º 19
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.º 20
0
 void replace(size_type i, const T& value) { increase(i, value - elems_[i]); }
Ejemplo n.º 21
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.º 22
0
void ChronoClass::increaseSystem(){
	if(systemTime != GetTickCount()){
		systemTime = GetTickCount();
		increase();
	}
}
Ejemplo n.º 23
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.º 24
0
void ChronoClass::increaseSleep(){
	increase();
	Sleep(1);
}
Ejemplo n.º 25
0
 void remove(Value newValue, bool isDecision = false) {if (newValue==inf) increase(newValue+1, isDecision); else if (newValue==sup) decrease(newValue-1, isDecision);}
 void update(int index, T new_value) {
     increase(index, new_value - readSingle(index));
 }
Ejemplo n.º 27
0
 void increase(ModifierFlag flag) { increase(Flags(flag)); }
Ejemplo n.º 28
0
void vsx_widget_2d_pager::event_mouse_down(vsx_widget_distance distance,vsx_widget_coords coords,int button) {
  distance.center.x > 0.0f ? increase() : decrease();
}
Ejemplo n.º 29
0
	void IceExceptionCounter::increase(Ice::Exception& e) {
		LOG_INFO("[" << fileName_ << "]-IceExceptionCounter::increase with " << e.what());
		increase();	
	}
Ejemplo n.º 30
0
Archivo: NEKey.cpp Proyecto: kniz/World
	NEKey NE_DLL &NEKey::operator++(int)
	{
		increase();

		return *this;
	}