Example #1
1
//! Determine the value corresponding to a specified point
double QwtWheel::getValue( const QPoint &p )
{
    // The reference position is arbitrary, but the
    // sign of the offset is important
    int w, dx;
    if ( orientation() == Qt::Vertical )
    {
        w = d_data->sliderRect.height();
        dx = d_data->sliderRect.y() - p.y();
    }
    else
    {
        w = d_data->sliderRect.width();
        dx = p.x() - d_data->sliderRect.x();
    }

    // w pixels is an arc of viewAngle degrees,
    // so we convert change in pixels to change in angle
    const double ang = dx * d_data->viewAngle / w;

    // value range maps to totalAngle degrees,
    // so convert the change in angle to a change in value
    const double val = ang * ( maxValue() - minValue() ) / d_data->totalAngle;

    // Note, range clamping and rasterizing to step is automatically
    // handled by QwtAbstractSlider, so we simply return the change in value
    return val;
}
void QmitkNumberPropertySlider::adjustFactors(short newDecimalPlaces, bool newShowPercents)
{
  int oldMax = maxValue();
  int oldMin = minValue();

  m_DecimalPlaces = newDecimalPlaces;
  m_ShowPercents = newShowPercents;

  m_FactorPropertyToSlider = pow(10.0,m_DecimalPlaces);
  m_FactorSliderToDisplay = 1.0 / m_FactorPropertyToSlider;

  // commented line would set the default increase/decrease to 1.0, no matter how many decimal places are available
  //setLineStep( ROUND(m_FactorPropertyToSlider) );

  if ( m_ShowPercents )
  {
    m_FactorPropertyToSlider *= 100.0;
    //setLineStep( ROUND(0.01 *m_FactorPropertyToSlider) );
    //setSuffix("%");
  }
  else
  {
    //setSuffix("");
  }

  setMinimum(oldMin);
  setMaximum(oldMax);
}
Example #3
0
void QRangeControl::addLine()
{
    if ( value() + lineStep() > value() )
	setValue( value() + lineStep() );
    else
	setValue( maxValue() );
}
//方法二:从根处搜索,不需要父指针,时间复杂度:O(h);
TreeNode * inOrderPredecessor1(TreeNode *root, TreeNode *node)
{
	if (!root)
	{
		return NULL;
	}
	if (node->left)
	{
		return maxValue(node->left);
	}
	TreeNode *succ=NULL;
	while (root)
	{
		if (node->val>root->val)
		{
			succ=root;
			root=root->right;
		}
		else if (node->val<root->val)
		{
			root=root->left;
		}
		else break;
	}
	return succ;
}
size_t AveragingAllocationStrategy::operator()(const size_t curBufferSize,
                                               const size_t increaseAmt)
{
   // The amount of memory to allocate is the larger of the requested size and
   // the average size computed from previous allocations.
   const size_t alloc_size(maxValue(curBufferSize + increaseAmt,
                                    computeAverage()));

   // Record the current amount allocated for future computations of the
   // average allocation amount. We accomplish this by first populating
   // mAllocSizes until its size equals mWindowSize. After that, we just
   // assign to the entry identified by mIndex.
   if ( mAllocSizes.size() < mWindowSize )
   {
      mAllocSizes.push_back(alloc_size);
   }
   else
   {
      mAllocSizes[mIndex] = alloc_size;
   }

   mIndex = (mIndex + 1) % mWindowSize;

   return alloc_size;
}
/*!
    Sets the minimum value of the range to \a minVal.

    If necessary, the maxValue() is adjusted so that the range remains
    valid.

    \sa minValue() setMaxValue()
*/
void QRangeControl::setMinValue( int minVal )
{
    int maxVal = maxValue();
    if ( maxVal < minVal )
	maxVal = minVal;
    setRange( minVal, maxVal );
}
Example #7
0
int AgentAB::minValue(int depth, int alpha, int beta) {
		//returns a value and an action in vector<int> ansMove
		//within the depth limit
		if (depth == 0)
				return eval(searchState_);
		int v = INT_MAX;
		vector<vector<int> >moveList = searchState_.successor(MIN);
		vector<vector<int> >::iterator iter;
		vector<int> tmpPos;
		for (iter = moveList.begin(); iter != moveList.end(); iter++) {
				tmpPos = searchState_.minPos;
				searchState_.update(MIN, *iter);
				int tmp = maxValue(depth - 1, alpha, beta);
				searchState_.moveBack(MIN, tmpPos);
				if (v > tmp) {
						v = tmp;
						if (depth == depthLimit) 
								ansMove = (*iter);														
				}				
				if (v <= alpha)
						return v;
				beta = min(v, beta);
		}
		return v;
}
Example #8
0
void QRangeControl::addPage()
{
    if ( value() + pageStep() > value() )
	setValue( value() + pageStep() );
    else
	setValue( maxValue() );
}
Example #9
0
//==============================================================================
value_type MoveSelector::minValue(
    const BitBoardPtr &spBoard,
    const value_type &depth,
    value_type alpha,
    value_type beta
) const
{
    ValidMoveSet vms(m_wpMoveSet, spBoard);
    value_type score = m_evaluator.Score(spBoard, vms);

    if (reachedEndState(depth, score))
    {
        return score;
    }

    MoveList moves = vms.GetMyValidMoves();
    value_type v = s_posInfinity;

    for (auto it = moves.begin(); it != moves.end(); ++it)
    {
        BitBoardPtr spResult = result(spBoard, *it);
        v = std::min(v, maxValue(spResult, depth-1, alpha, beta));

        if (score <= alpha)
        {
            return v;
        }

        beta = std::min(beta, v);
    }

    return v;
}
Example #10
0
void SliderBase::wheelEvent(QWheelEvent *e)
{
	if(_ignoreMouseWheel)
	{
		e->ignore();
		return;
	}

	e->accept();

	float inc = (maxValue() - minValue()) / 40;
	if (e->modifiers() == Qt::ShiftModifier)
		inc = inc / 10;

	if (inc < step())
		inc = step();

	if (e->delta() > 0)
		setValue(value() + inc);
	else
		setValue(value() - inc);

	emit sliderMoved(value(), _id);
	emit sliderMoved((int)value(), _id);
}
Example #11
0
/**
 * [isBST description]
 * @param  node [description]
 * @return      [description]
 */
int isBST(struct node* node)
{
  if(node == NULL)
  {
    return 1;
  }
  else
  {
    if((node->left != NULL) && (minValue(node->left) > node->data))
    {
      return 0;
    }

    if((node->right != NULL) && (maxValue(node->right) <= node->data))
    {
      return 0;
    }

    if(!isBST(node->left) || !isBST(node->right))
    {
      return 0;
    }

    return 1;
  }
}
Example #12
0
void KDoubleSpinBox::setLineStep( double step ) {
  bool ok = false;
  if ( step > maxValue() - minValue() )
    base::setLineStep( 1 );
  else
    base::setLineStep( kMax( d->mapToInt( step, &ok ), 1 ) );
}
int main(void){
	int m,n;
	while(scanf("%d %d",&m,&n)!=EOF&&0<m&&m<=1000&&0<n&&n<=1000){
		int **arr=(int **)malloc(m*sizeof(int *));
		if(arr==NULL){
			printf("malloc fail\n");
			return -1;
		}
		//输入数据 
		int i=0;
		for(;i<m;i++){
			arr[i]=(int *)malloc(n*sizeof(int));
			if(arr[i]==NULL){
				printf("malloc fail\n");
				return -1;
			}
			int j=0;
			for(;j<n;j++){
				scanf("%d",&arr[i][j]);
			}
		}
		int res=maxValue(arr,m,n); 
		printf("%d\n",res);
	}
	return 0;
}
Example #14
0
int maxIndex(int arr[], int size)
{
	int i;
	int o = maxValue(arr, size);
	for (i = 0; i < size; i++)
		if (arr[i] == o)
			return i;
}
Example #15
0
/*!
  \brief Notify a change of the range

  Called by QwtAbstractSlider
*/
void QwtKnob::rangeChange()
{
    if ( autoScale() )
        rescale( minValue(), maxValue() );

    layoutKnob( true );
    recalcAngle();
}
Example #16
0
void KDoubleNumInput::updateLegacyMembers() {
    // ### update legacy members that are either not private or for
    // which an inlined getter exists:
    m_lower = minValue();
    m_upper = maxValue();
    m_step = d->spin->lineStep();
    m_specialvalue = specialValueText();
}
Example #17
0
double LpaStar::calc_H(int x, int y) {

    int diffY = abs(goal->y - y);
    int diffX = abs(goal->x - x);

    //maze[y][x].h = (double)maxValue(diffY, diffX);
    return (double)maxValue(diffY, diffX);
}
Example #18
0
int main(int argc, char const *argv[])
{	
	printf("请输入三个数,求最大值:\n");
	int a,b,c;
	scanf("%d,%d,%d",&a,&b,&c);

	printf("最大值:%d\n",maxValue(a,b,c));
	return 0;
}
Example #19
0
int QwtThermo::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setValue((*reinterpret_cast< double(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 1;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< bool*>(_v) = alarmEnabled(); break;
        case 1: *reinterpret_cast< double*>(_v) = alarmLevel(); break;
        case 2: *reinterpret_cast< ScalePos*>(_v) = scalePosition(); break;
        case 3: *reinterpret_cast< int*>(_v) = spacing(); break;
        case 4: *reinterpret_cast< int*>(_v) = borderWidth(); break;
        case 5: *reinterpret_cast< double*>(_v) = maxValue(); break;
        case 6: *reinterpret_cast< double*>(_v) = minValue(); break;
        case 7: *reinterpret_cast< int*>(_v) = pipeWidth(); break;
        case 8: *reinterpret_cast< double*>(_v) = value(); break;
        }
        _id -= 9;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setAlarmEnabled(*reinterpret_cast< bool*>(_v)); break;
        case 1: setAlarmLevel(*reinterpret_cast< double*>(_v)); break;
        case 2: setScalePosition(*reinterpret_cast< ScalePos*>(_v)); break;
        case 3: setSpacing(*reinterpret_cast< int*>(_v)); break;
        case 4: setBorderWidth(*reinterpret_cast< int*>(_v)); break;
        case 5: setMaxValue(*reinterpret_cast< double*>(_v)); break;
        case 6: setMinValue(*reinterpret_cast< double*>(_v)); break;
        case 7: setPipeWidth(*reinterpret_cast< int*>(_v)); break;
        case 8: setValue(*reinterpret_cast< double*>(_v)); break;
        }
        _id -= 9;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 9;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 9;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 9;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 9;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 9;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 9;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #20
0
void PosEdit::updateButtons()
      {
      bool upEnabled   = isEnabled() && (pos() < maxValue());
      bool downEnabled = isEnabled() && (pos() > minValue());

      //printf("PosEdit::updateButtons smpte:%d upEnabled:%d downEnabled:%d\n", smpte(), upEnabled, downEnabled);

      controls->setStepEnabled(upEnabled, downEnabled);
      }
Example #21
0
int QProg::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: valueChanged((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 1: setValue((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 2: setMaxValue((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 3: setMinValue((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 4: setFontDim((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 5: setPrecision((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 6: setBarColor((*reinterpret_cast< QColor(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 7;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< double*>(_v) = value(); break;
        case 1: *reinterpret_cast< double*>(_v) = minValue(); break;
        case 2: *reinterpret_cast< double*>(_v) = maxValue(); break;
        case 3: *reinterpret_cast< int*>(_v) = font(); break;
        case 4: *reinterpret_cast< int*>(_v) = numPrec(); break;
        case 5: *reinterpret_cast< QColor*>(_v) = color(); break;
        }
        _id -= 6;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setValue(*reinterpret_cast< double*>(_v)); break;
        case 1: setMinValue(*reinterpret_cast< double*>(_v)); break;
        case 2: setMaxValue(*reinterpret_cast< double*>(_v)); break;
        case 3: setFontDim(*reinterpret_cast< int*>(_v)); break;
        case 4: setPrecision(*reinterpret_cast< int*>(_v)); break;
        case 5: setBarColor(*reinterpret_cast< QColor*>(_v)); break;
        }
        _id -= 6;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 6;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 6;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 6;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 6;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 6;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 6;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #22
0
bool AI::makeMove(SDL_Event *event){

    // Init enemyTeam that this class can use
    getEnemyTeam();

    for(int index=0;index<team.size();index++){
        currentIndex = index;

        team[index].directionValues[0] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, LEFT);
        team[index].directionValues[1] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, RIGHT);

        if (team[index].isKing()) {
            team[index].directionValues[3] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, BACK_RIGHT);
            team[index].directionValues[2] = maxValue(Board->virtualBoard, team, enemyTeam, MAX_DEPTH, BACK_LEFT);
        }
        cout<<"Index: "<<index<<" ("<< team[index].x << "," << team[index].y;
        cout<<") Left: "<<team[index].directionValues[0]<<" Right: "<<team[index].directionValues[1];
        cout<<" bLeft: "<<team[index].directionValues[2]<<" bRight: "<<team[index].directionValues[3]<<endl;

        team[index].findBestDirection();
        team[index].findLargestPotenial();
    }

    int bestPieceIndex = bestPiece(team);
    cout<< "The chosen one: " << bestPieceIndex << " -> ("<< team[bestPieceIndex].x << "," << team[bestPieceIndex].y;

    int x = team[bestPieceIndex].x;
    int y = team[bestPieceIndex].y;

    // Makes sure the move isnt out of bounds //
    if (team[bestPieceIndex].potential != OUT_OF_BOUND) {

        changeWithDirection(x, y, team[bestPieceIndex].bestDirection, false);

        if(sameTeam(Board->virtualBoard[x][y],ENEMY_TEAM_NUMBER)){
            // Changes it again for moving 2 units diagonally //
            changeWithDirection(x, y, team[bestPieceIndex].bestDirection, false);
        }
        cout<<") best move: (" << x << "," << y <<")"<< endl;
        movePiece(Board->virtualBoard, team, bestPieceIndex, x, y);
        return true;
    }
    return false;
}
Example #23
0
/*!
 * \brief ET0_Penman_hourly http://www.cimis.water.ca.gov/cimis/infoEtoPmEquation.jsp
 * \param heigth elevation above mean sea level (meters)
 * \param normalizedTransmissivity normalized tramissivity [0-1] ()
 * \param globalSWRadiation net Short Wave radiation (W m-2)
 * \param airTemp air temperature (C)
 * \param airHum relative humidity (%)
 * \param windSpeed10 wind speed at 2 meters (m s-1)
 * \return result
 */
double ET0_Penman_hourly(double heigth, double normalizedTransmissivity, double globalSWRadiation,
                double airTemp, double airHum, double windSpeed10)
{
    double mySigma;                              /*!<  Steffan-Boltzman constant J m-2 h-1 K-4 */
    double es;                                   /*!<  saturation vapor pressure (kPa) at the mean hourly air temperature in C */
    double ea;                                   /*!<  actual vapor pressure (kPa) at the mean hourly air temperature in C */
    double emissivity;                           /*!<  net emissivity of the surface */
    double netRadiation;                         /*!<  net radiation (J m-2 h-1) */
    double netLWRadiation;                       /*!<  net longwave radiation (J m-2 h-1) */
    double g;                                    /*!<  soil heat flux density (J m-2 h-1) */
    double Cd;                                   /*!<  bulk surface resistance and aerodynamic resistance coefficient */
    double tAirK;                                /*!<  air temperature (Kelvin) */
    double windSpeed2;                           /*!<  wind speed at 2 meters (m s-1) */
    double delta;                                /*!<  slope of saturation vapor pressure curve (kPa C-1) at mean air temperature */
    double pressure;                             /*!<  barometric pressure (kPa) */
    double lambda;                               /*!<  latent heat of vaporization in (J kg-1) */
    double gamma;                                /*!<  psychrometric constant (kPa C-1) */
    double firstTerm, secondTerm, denominator;


    es = computeSatVapPressure(airTemp);
    ea = airHum * es / 100.0;
    emissivity = emissivityFromVaporPressure(ea);
    tAirK = airTemp + ZEROCELSIUS;
    mySigma = STEFAN_BOLTZMANN * HOUR_SECONDS;
    netLWRadiation = minValue(normalizedTransmissivity, 1) * emissivity * mySigma * (pow(tAirK, 4));

    /*!   from [W m-2] to [J h-1 m-2] */
    netRadiation = ALBEDO_CROP_REFERENCE * (3600 * globalSWRadiation) - netLWRadiation;

    /*!   values for grass */
    if (netRadiation > 0)
    {   g = 0.1 * netRadiation;
        Cd = 0.24;
    }
    else
    {
        g = 0.5 * netRadiation;
        Cd = 0.96;
    }

    delta = SaturationSlope(airTemp, es) / 1000;    /*!<  to kPa */

    pressure = 101.3 * pow(((293 - 0.0065 * heigth) / 293), 5.26);

    gamma = Psychro(pressure, airTemp);
    lambda = LatentHeatVaporization(airTemp);

    windSpeed2 = windSpeed10 * 0.748;

    denominator = delta + gamma * (1 + Cd * windSpeed2);
    firstTerm = delta * (netRadiation - g) / (lambda * denominator);
    secondTerm = (gamma * (37 / tAirK) * windSpeed2 * (es - ea)) / denominator;

    return maxValue(firstTerm + secondTerm, 0);
}
Example #24
0
void heapSort(int keys[], int numKeys){
    if(numKeys == 0) return;
    heapHndl H = newHeap(numKeys);
    for(int i = 0; i < numKeys; i++) insert(H, keys[i]);
    for(int i = numKeys-1; i > -1; i--){
        keys[i] = maxValue(H);
        deleteMax(H);
    }
    freeHeap(&H);
}
int isBST2(struct node *node) {
	if (node == NULL) return;

	else {
		int min = minValue(node);
		int max = maxValue(node);
	
		return (isBSTRecur(node,min,max));
	}
}
void Foam::distributionModel::check() const
{
    if (minValue() < 0)
    {
        FatalErrorInFunction
            << type() << "distribution: Minimum value must be greater than "
            << "zero." << nl << "Supplied minValue = " << minValue()
            << abort(FatalError);
    }

    if (maxValue() < minValue())
    {
        FatalErrorInFunction
            << type() << "distribution: Maximum value is smaller than the "
            << "minimum value:" << nl << "    maxValue = " << maxValue()
            << ", minValue = " << minValue()
            << abort(FatalError);
    }
}
Example #27
-1
/*!
  \brief Recalculate the marker angle corresponding to the
    current value
*/
void QwtKnob::recalcAngle()
{
    // calculate the angle corresponding to the value
    if ( maxValue() == minValue() )
    {
        d_data->angle = 0;
        d_data->nTurns = 0;
    }
    else
    {
        d_data->angle = ( value() - 0.5 * ( minValue() + maxValue() ) )
            / ( maxValue() - minValue() ) * d_data->totalAngle;
        d_data->nTurns = qFloor( ( d_data->angle + 180.0 ) / 360.0 );
        d_data->angle = d_data->angle - d_data->nTurns * 360.0;
    }
}
Example #28
-1
void Slider::rangeChange()
{
	if (!hasUserScale())
		d_scale.setScale(minValue(), maxValue(), d_maxMajor, d_maxMinor);
	SliderBase::rangeChange();
	repaint();
}
Example #29
-1
void LinearGauge::saveSettings( QSettings& pSettings )
{
	// Range
	pSettings.setValue("orientation", orientation());
	pSettings.setValue("scalePosition", scalePosition());
	pSettings.setValue("minValue", minValue());
	pSettings.setValue("maxValue", maxValue());

	// Ticks
	pSettings.setValue("scaleMaxMajor", scaleMaxMajor());
	pSettings.setValue("scaleMaxMinor", scaleMaxMinor());
	pSettings.setValue("labels", scaleDraw()->hasComponent( QwtAbstractScaleDraw::Labels ));
	pSettings.setValue("font", font().family());
	pSettings.setValue("fontSize", font().pointSize());

	// Pipe
	pSettings.setValue("value", value());
	pSettings.setValue("pipeWidth", pipeWidth());
	pSettings.setValue("pipeColor", fillBrush().color().rgb());

	// Alarm
	pSettings.setValue("alarmEnabled", alarmEnabled());
	pSettings.setValue("alarmLevel", alarmLevel());
	pSettings.setValue("alarmBrush", alarmBrush().color().rgb());

	// Color
	pSettings.setValue("textColor", textColor().rgb());
	pSettings.setValue("backgroundColor", backgroundColor().rgb());

	AbstractGauge::saveSettings( pSettings );
}
Example #30
-1
/*! 
  Update the scale with the current attributes
  \sa QwtDial::setScale
*/
void QwtDial::updateScale()
{
    if ( d_scaleDraw )
    {
        d_scaleDraw->setScale(minValue(), maxValue(),
            d_maxMajIntv, d_maxMinIntv, d_scaleStep);
    }
}