示例#1
0
文件: main.c 项目: conghui/books
static void draw_vertical_histogram(int *word_len, int size)
{
    int *scaled_word_len;
    int i;
    int max;
    int scaled_max;

    scaled_word_len = malloc(size * sizeof *scaled_word_len);
    max = max_value(word_len, size);

    for (i = 0; i < size; i++) {
        scaled_word_len[i] = scaled(word_len[i], max);
    }

    scaled_max = max_value(scaled_word_len, size);
    for (i = scaled_max; i > 0; i--) {
        int j;
        for (j = 1; j < WORD_MAX_LENGTH; j++) {
            if (scaled_word_len[j] >= i) {
                scaled_word_len[j]--;
                printf("%3c", '*');
            }
            else {
                printf("%3c", ' ');
            }
        }
        putchar('\n');
    }

    for (i = 1; i < size; i++) {
        printf("%3d", i);
    }
    putchar('\n');
}
示例#2
0
		void update_test_vector_count()
		{
			test_vector_count_ = 0;

			// TODO: Check polynomial range and throw exception if too large
			if (polynomial_ > 0) {
				test_vector_count_ = 1;
			} else if (polynomial_range_) {
				test_vector_count_ = (uint64_t)polynomial_end_ - (uint64_t)polynomial_start_;
			} else {
				test_vector_count_ = (uint64_t)max_value(crc_width_);
			}

			if (probe_final_xor_)
				test_vector_count_ *= (uint64_t)max_value(crc_width_);

			if (probe_initial_)
				test_vector_count_ *= (uint64_t)max_value(crc_width_);

			if (probe_reflected_input_)
				test_vector_count_ *= 2;

			if (probe_reflected_output_)
				test_vector_count_ *= 2;

		}
double MRFMap::pairwiseMax(const EdgeInfo &edge) const
{
    return max_value(labelRange(), [&] (size_t l1) {
        return max_value(labelRange(), [&] (size_t l2) {
            return _mrf.getPairwise(edge.index, l1, l2)
                + _dualVariables[edge.index][0][l1]
                + _dualVariables[edge.index][1][l2];
        });
    });
}
示例#4
0
double		max_value(t_tree tree, double max)
{
  if (!tree)
    return (max);
  if (tree->value > max)
    max = tree->value;
  if (tree->left)
    return (max_value(tree->left, max));
  if (tree->right)
    return (max_value(tree->right, max));
}
示例#5
0
int isStackSortable(int * array, int len)
{
  if(len < 3)
    { 
      return TRUE ;
    }
  int max_index = max_value(array, len) ;
  int left_max ;
  int right_min ;
  if(max_index == 0)
    {
      left_max = 0 ;
      right_min = array[min_value(array+1,len-1) + 1] ;
      if(left_max > right_min)
	{
	  return FALSE ;
	}
      return isStackSortable(array+1, len-1) ;
    }
  if(max_index == (len-1) )
    {
      left_max = array[max_value(array,len-1)];
      right_min = array[len-1] ;
      if(left_max > right_min)
	{
	  return FALSE ;
	}
      return isStackSortable(array, len-1) ;
    }

  left_max = array[max_value(array,max_index)] ;
  right_min = array[min_value(array+max_index+1,(len -max_index - 1) )+ max_index+1] ;
  if(left_max > right_min) 
    {
      return FALSE ;
    }
  int  left =  isStackSortable(array,max_index) ;
  int right =  isStackSortable(array+max_index+1,(len-max_index-1)) ;

  if(left == TRUE && right == TRUE)
    {
      return TRUE ;
    }
  else 
    {
      return FALSE ;
    }

    
}
示例#6
0
AOVoxelTree::AOVoxelTree(
    const Scene&    scene,
    const GScalar   max_extent_fraction)
{
    assert(max_extent_fraction > GScalar(0.0));

    // Print a progress message.
    RENDERER_LOG_INFO("building ambient occlusion voxel tree...");

    // Compute the bounding box of the scene.
    const GAABB3 scene_bbox = scene.compute_bbox();

    // Compute the maximum extent of a leaf, in world space.
    const GScalar max_extent = max_extent_fraction * max_value(scene_bbox.extent());

    // Build the tree.
    BuilderType builder(m_tree, scene_bbox, max_extent);
    build(scene, builder);
    builder.complete();

    // Print statistics.
    TreeStatisticsType tree_stats(m_tree, builder);
    RENDERER_LOG_DEBUG("ambient occlusion voxel tree statistics:");
    tree_stats.print(global_logger());
}
int computer_move(char **board,char piece1,char piece2) {
  //perform minimax + alpha-beta pruning algorithm
  int minimax = max_value(piece1, piece2, -1000000, 1000000, board, 1); 
  //assign next move of computer
  board[comp_x][comp_y] = piece1;	
  return 1;
}
int min_value(char piece1, char piece2, int a, int b, char **board, int currstate) {
  int utility=terminal_test(board), x, y, minimax=100000, temp;

  //if bottom of tree reached
  if (terminal_test(board)!=INCOMPLETE)	{
    //return utility value of the board
    return utility;
  }
	
  for (x=0; x<3; x++) {
    for (y=0; y<3; y++) {
      if (board[x][y]==BLANK) {							
        //for each successor of the current board
	board[x][y]=piece1;
	//get minimax value of its successor
	temp=max_value(piece2, piece1, a, b, board, 0); 
	//find minimum of all minimax values of its successors
	if (temp<minimax) {							
	  minimax=temp;	
	}
	//if minimax value of a successor <= alpha of its predecessor
	if (minimax<=a) {
          //skip this node since predecessor will never choose this node
	  board[x][y]=BLANK;						
	  return minimax;
	}	
	b=min(b, minimax);	
	board[x][y]=BLANK;	
      }	
    }
  }
  return minimax;	
}
示例#9
0
void find_meeting_schedule(int slots[][],int n){
  //Busy slot Tracker(in which meeting can't be arranged at any cost) in four variables
  int from=0,to=0;
  int i;
  int temp_from,temp_to;

  for(i=0;i<n;i++){
	 temp_from=convert_to_minute(slot[i][0],slot[i][1]);
	 temp_to=convert_to_minute(slot[i][2],slot[i][3]);
	 if(temp_from>temp_to){
				printf("Slots not in order");
				return; }

	 //is this first busy slot?if yes! store busy schedule in four variables declared above
	 if(i==0){
				from=temp_from;
				to=temp_to;
				continue;}
	 if(temp_from<=to)from=min_value(from,temp_from);
	 else {meeting_from=from;meeting_to=temp_from;}

	 if(temp_to>=from)to=max_value(to,temp_to);
	 else {meeting_to=from;meeting_to=temp_from;}


















  }

















}
示例#10
0
bool is_bst1(tree_node* T)
{
/*
Returns true if a binary tree is a binary search tree.
*/

  if(T!=NULL)
    {
      bool is_leaf = (T->left ==NULL) && (T->right == NULL);
      if(is_leaf) 
	return true;

      if(max_value(T) <= T->data && T->right !=NULL)
	return false;
      
      if(min_value(T) > T->data && T->left!=NULL)
	return false;

      if(!is_bst1(T->left))
	return false;

      if(!is_bst1(T->right))
	return false;

      return true;
    }
  else
    return true;
}
position* TicTacToeState::get_move()
{
    position* p = NULL;
    // Initialize random seed
    srand (time(NULL));
    // Get a random number for a move
    int r = rand() % 10;

    // esay mode will have 70% random moves
    // hard mode will have 50% random moves
    // impossivle mode will no random moves
    if ((mode == "easy" && r >= 3) ||
        (mode == "hard" && r >= 5) )
        index = rand() % actions.size(); 
    else 
    {
        unsigned int depth = 0;
        // 'O' always tries to minimize the value
        // 'X' always tries to maximize the value
        if (player == p2_symbol)
            min_value(depth);
        else 
            max_value(depth);
    }

    p = &actions[index];
	return p;
}
示例#12
0
ExpectimaxNode chance_node(int* board, int depth) {
    int successor_amount = amount_of_successors(board);
    int** successors = generate_successors_chance(board);

    double vs = 0;
    double count = 0;

    for (int i=0; i < successor_amount; i++) {
        ExpectimaxNode node = max_value(successors[i], depth);
        double heuristic = node.heuristic;

        double probability = (successor_tiles[i] == TILE_2_VALUE) ? 0.9 : 0.1;
        double value = probability * heuristic;

        vs += value;
        count++;
    }

    for (int i = 0; i < successor_amount; i++) {
        free(successors[i]);
    }
    free(successors);

    return create_expectimax_node(-1, vs / count);
}
示例#13
0
	void WaveletMatrix::build_level(uint **bm, uint *symbols, uint length, uint *occs) {
		uint sigma = max_value(symbols, length);
		uint *new_order = new uint[sigma + 1];
		for (uint level = 0; level < height; level++) {
			uint zeroes = 0;
			for (uint i = 0; i < sigma + 1; i++)
			if (!is_set(i, height - level - 1)) {
				new_order[i] = 0;
			}
			else {
				new_order[i] = 1;
			}
			for (uint i = 0; i < length; i++)
				if (!new_order[symbols[i]])
					zeroes++;
			uint *new_symbols = new uint[length];
			uint new_pos0 = 0, new_pos1 = zeroes;
			for (uint i = 0; i < length; i++) {
				if (!new_order[symbols[i]]) {
					new_symbols[new_pos0++] = symbols[i];
					bitclean(bm[level], i);
				}
				else {
					new_symbols[new_pos1++] = symbols[i];
					bitset(bm[level], i);
				}
			}
			delete [] symbols;
			symbols = new_symbols;
		}
		delete [] symbols;
		delete [] new_order;
	}
示例#14
0
void rtlr::initialize(multilayer_perceptron* mlp)
{
    assert(mlp);

    _mlp = mlp;
    _netValueDerivates = _mlp->_netValueDerivates.get_arrays() | to_vector();
    _pValuesPool = _mlp->context()->device_array_management()->create_pool(false);
    _uLayersCount = _mlp->_layers.size() - 1;
    _maxULayerSize = _mlp->_layers |
    where([](row_numbered<layer_ptr>& l) { return l.row_num() != 0; }) |
    max_value([](row_numbered<layer_ptr>& l) { return l.value()->size(); });
    
    for (idx_t lidx = 1; lidx < _mlp->_layers.size(); lidx++)
    {
        _inputLayerInfos.emplace_back();
        _pValues.emplace_back();
        auto& layer = _mlp->_layers[lidx].value();
        _pValues.back().emplace_back(create_p_values_for_weights(_mlp->_biases.get(lidx)));
        for (auto& inputLayer : layer->input_layers())
        {
            idx_t iidx = _mlp->get_layer_index(inputLayer);
            _inputLayerInfos.back().emplace_back();
            auto& info = _inputLayerInfos.back().back();
            info.index = iidx - 1;
            info.size = inputLayer->size();
            info.weights = _mlp->_weights.get(make_pair(iidx, lidx));
            info.is_element_of_u = inputLayer != _mlp->_layers[0].value();
            _pValues.back().emplace_back(create_p_values_for_weights(info.weights));
        }
    }

    _pValuesPool->allocate();
}
示例#15
0
文件: period.c 项目: Vistarino/pandas
npy_int64 get_daytime_conversion_factor(int index1, int index2)
{
    if (daytime_conversion_factor_matrix == NULL) {
        initialize_daytime_conversion_factor_maxtrix();
    }
    return daytime_conversion_factor_matrix[min_value(index1, index2)][max_value(index1, index2)];
}
示例#16
0
   static SizeType get(const SizeType max_size
                     ,const SizeType capacity
                     ,const SizeType n)
   {
      const SizeType remaining = max_size - capacity;
      if ( remaining < n )
         geofeatures_boost::container::throw_length_error("get_next_capacity, allocator's max_size reached");
      const SizeType m3 = max_size/3;

      if (capacity < m3)
         return capacity + max_value(3*(capacity+1)/5, n);

      if (capacity < m3*2)
         return capacity + max_value((capacity+1)/2, n);
      return max_size;
   }
示例#17
0
void print_graph_at_size(double * values, int pointCount, int cols, int rows) {
  double * columns = scale_graph(values, pointCount, cols);
  double maxValue = max_value(columns, cols);

  int row, col;
  for (col = 0; col < cols+2; ++col) {
    printf("-");
  }
  printf("\n");
  for (row = rows; row > 0; --row) {
    printf("|");
    for (col = 0; col < cols; ++col) {
      int height = (int)lround((double)rows * columns[col] / maxValue);
      if (height >= row) {
        printf("#");
      } else {
        printf(" ");
      }
    }
    printf("|\n");
  }
  for (col = 0; col < cols+2; ++col) {
    printf("-");
  }
  printf("\n");

  free(columns);
}
示例#18
0
double		btree_get_max_value(t_tree tree)
{
  double	max;

  max = 0;
  return (max_value(tree, max));
}
示例#19
0
/**
 * Method for estimating aoa of incident infrared light. Returns value between
 * 0 and 360. If measurement is not reliable i.e. received light intensity was
 * not high enough, this method returns negative value.
 */
float AoAPlug::get_aoa_deg() {
  set_values();
  // if double_peak() is implemented change force version
  if (max_value()<MAX_VAL_THRESHOLD) {
    return AOA_DEG_FAIL;
  }
  return calculate_aoa();
}
示例#20
0
int max_value(bst *b)
{
	if(!b)
		return INT_MAX;
	if(!b->right)
		return b->val;
	return max_value(b->right);
}
示例#21
0
		void set_crc_width(uint16_t var) { 
			crc_width_ = var; 
			update_test_vector_count(); 
			polynomial_range_ = false;
			polynomial_start_ = 0;
			polynomial_end_ = max_value(crc_width_);
			update_test_vector_count();
		}
void 
hsv_v_filter(FILTER_DESC *filter_desc)
{
	// http://en.wikipedia.org/wiki/HSL_and_HSV
	// http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet2/t_convert.html
	
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER_LIST *n_list = NULL;
	NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
	int nl_number, p_number;
	int xo, yo, wi, hi, wo, ho;
	int r, g, b;

	// Checks the Neuron Layers Number
	for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
            	;

	// Checks the Parameters Number
	for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
            	;

	if (p_number != 1)
	{
		Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", "");
		return;
	}

	// Gets the Input Neuron Layer
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Gets the Filter Output 
	nl_output = filter_desc->output;
	
	// Input-Output width
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;

	wo = nl_output->dimentions.x;
	ho = nl_output->dimentions.y;
	
	if (wi != wo || hi != ho)
	{
		Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", "");
		return;
	}
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{
			r = RED(nl_input->neuron_vector[xo + yo * wo].output.ival);
			g = GREEN(nl_input->neuron_vector[xo + yo * wo].output.ival);
			b = BLUE(nl_input->neuron_vector[xo + yo * wo].output.ival);
			
			nl_output->neuron_vector[xo + yo * wo].output.ival = max_value(r, g, b);
		}
	}
}
示例#23
0
文件: chart.c 项目: phoenixgao/fdubbs
int draw_chart(const struct bbsstat *st)
{
	char *blk[NUMBLKS] = {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"};

	int max = max_value(st);
	int item = (max + MAX_HEIGHT - 1)/ MAX_HEIGHT;
	if (item == 0)
		item = 1;
	max = item * MAX_HEIGHT;

	int i, j, height, lastcolor, left;
	char str[20], fstr[20];
	char *mg = left_margin(item, &left);
	sprintf(fstr, "\033[1;%%dm%%%dd│", left);
	if (max < 1000)
		printf("\033[1;37m%s ┌────────────────────────────────────\n", mg);
	else
		printf("\033[1;37m%s ┌────超过1000只显示前三位数字────────────────────\n", mg);
	for (i = MAX_HEIGHT + 1; i > 0; --i) {
		lastcolor = ANSI_COLOR_WHITE;
		printf(fstr, lastcolor, i * item);
		for (j = 0; j < MAX_BARS; ++j) {
			height = st->value[j] * NUMBLKS * MAX_HEIGHT / max;
			if (height >= i * NUMBLKS) {
				if (lastcolor == st->color[j]) {
					printf("%s ", blk[NUMBLKS - 1]);
				} else {
					lastcolor = st->color[j];
					printf("\033[%dm%s ", lastcolor, blk[NUMBLKS - 1]);
				}
			} else if (height > (i - 1) * NUMBLKS && height < i * NUMBLKS) {
				if (lastcolor == st->color[j]) {
					printf("%s ", blk[height % NUMBLKS - 1]);
				} else {
					lastcolor = st->color[j];
					printf("\033[%dm%s ", lastcolor, blk[height % NUMBLKS - 1]);
				}
			} else if (height > (i - 2) * NUMBLKS && height <= (i - 1) * NUMBLKS) {
				if (st->value[j] == 0)
					sprintf(str, "   ");
				else
					sprintf(str, "%d", st->value[j]);
				if (lastcolor == ANSI_COLOR_WHITE) {
					printf("%-3.3s", str);
				} else {
					lastcolor = ANSI_COLOR_WHITE;
					printf("\033[%dm%-3.3s", lastcolor, str);
				}
			} else {
				printf("   ");
			}
		}
		printf("\n");
	}
	return item;	
}
示例#24
0
 static SizeType get(const SizeType max_size
                    ,const SizeType capacity
                    ,const SizeType n)
 {
    const SizeType remaining = max_size - capacity;
    if ( remaining < n )
       geofeatures_boost::container::throw_length_error("get_next_capacity, allocator's max_size reached");
    const SizeType additional = max_value(n, capacity);
    return ( remaining < additional ) ? max_size : ( capacity + additional );
 }
/**
 * Alpha beta search with time, memory, and depth cutoff
 *
 * @param game_state a game tree root
 * @return a move
 */
struct Move * alpha_beta_search( struct GameNode * game_state )
{
    int v = max_value( game_state, 0, INT_MIN, INT_MAX );

    //printf( "Best util val: %d\n", game_state->best_util_val );
    //printf( "Max val : %d\n", v );
    //printf( "Best move: " );
    //print_move( game_state->best_move );
    
    return game_state->best_move;
}
示例#26
0
int main(void)
{
	int first, second;
	
	printf("\nPlease enter 2 integers: ");
	scanf("%d %d", &first, &second);
	max_value(&first, &second); //sends addresses to function
	printf("Both values are now %d %d\n\n", first, second);
	
	return 0;
}
示例#27
0
文件: period.c 项目: Vistarino/pandas
static int calc_conversion_factors_matrix_size() {
    int matrix_size = 0;
    int index;
    for (index=0;; index++) {
        int period_value = get_freq_group_index(daytime_conversion_factors[index][0]);
        if (period_value == 0) {
            break;
        }
        matrix_size = max_value(matrix_size, period_value);
    }
    return matrix_size + 1; 
}
示例#28
0
int main()
{
    int n, c;
    scanf("%d %d", &n, &c);
    int i;
    for (i = 1; i <= n; i++)
    {
      scanf("%d %d", &weight[i], &value[i]); 
    }
    int max = max_value (n, c);
    printf("%d\n", max);
    return 0;
}
示例#29
0
double Stencil::shift_kernel_range()
{
  // Updates kernel values from 0 --> max_value range to stencil_range_min --> stencil_range_max
  // kernel[i][j] = stencil_range_min + (2 * stencil_range_max * PGM value) / (PGM max_value)

  assert(max_value() != 0);
  double kernel_sum = 0.0;

  double old_value;
  double new_value;

  for (int i=0; i < rows(); i++) {
    for (int j=0; j < columns(); j++) {
      old_value = kernel->get(i, j);
      new_value = (double) stencil_range_min + (2 * stencil_range_max * old_value) / max_value();
      new_value = round(new_value);
      kernel->set(new_value , i, j);
      kernel_sum += new_value;
    }
  }

  return round(kernel_sum);
}
UStatus
ua_sensors_orientation_get_max_value(
    UASensorsOrientation* sensor,
    float* value)
{
    if (sensor == NULL || value == NULL)
        return U_STATUS_ERROR;

    ALOGI("%s():%d", __PRETTY_FUNCTION__, __LINE__);
    auto s = static_cast<ubuntu::application::sensors::Sensor*>(sensor);
    *value = s->max_value();

    return U_STATUS_SUCCESS;
}