Exemplo n.º 1
0
int layout_search_box(const char *search_ID, layout_object_mask_t obj_types, int x1, int y1, int x2, int y2)
{
  BoxType spot;
	layout_search_t *s = new_search(search_ID);

	spot.X1 = x1;
	spot.Y1 = y1;
	spot.X2 = x2;
	spot.Y2 = y2;

	s->layer = -1;
	if (obj_types & OM_LINE) {
		s->searching = OM_LINE;
		r_search (CURRENT->line_tree, &spot, NULL, search_callback, s);
	}

	if (obj_types & OM_TEXT) {
		s->searching = OM_TEXT;
		r_search (CURRENT->text_tree, &spot, NULL, search_callback, s);
	}

	if (obj_types & OM_ARC) {
		s->searching = OM_ARC;
		r_search (CURRENT->arc_tree, &spot, NULL, search_callback, s);
	}

	if (obj_types & OM_VIA) {
		s->searching = OM_VIA;
		r_search (PCB->Data->via_tree, &spot, NULL, search_callback, s);
	}

	if (obj_types & OM_PIN) {
		s->searching = OM_PIN;
		r_search (PCB->Data->pin_tree, &spot, NULL, search_callback, s);
	}

	if (obj_types & OM_POLYGON) {
		s->searching = OM_POLYGON;
		for (s->layer = 0; s->layer < MAX_LAYER + 2; s->layer++)
			r_search (PCB->Data->Layer[s->layer].polygon_tree, &spot, NULL, search_callback, s);
		s->layer = -1;
	}

	return s->used;
}
Exemplo n.º 2
0
static int layout_search_flag(const char *search_ID, multiple layout_object_mask_t obj_types, int flag)
{
	Cardinal l, n;
	layout_search_t *s = new_search(search_ID);
	LayerType *layer = PCB->Data->Layer;

	for (l =0; l < MAX_LAYER + 2; l++, layer++) {
		s->layer = l;
		select(s, OM_ARC,     flag, layer->Arc);
		select(s, OM_LINE,    flag, layer->Line);
		select(s, OM_TEXT,    flag, layer->Text);
		select(s, OM_POLYGON, flag, layer->Polygon);
	}
	select(s, OM_VIA,  flag, PCB->Data->Via);
//	select(s, OM_PIN,  flag, PCB->Data->Pin,  PCB->Data->PinN); /* TODO */

	return s->used;
}
Exemplo n.º 3
0
void file_translation::run(){
	string line;
	while(!fin.eof()){
		getline(fin, line);
		char* str = (char*)line.c_str();
		char* pch = strtok (str," ,.-?!");
		while(pch != NULL){
			printf("%s\n", pch);
		    search_strategy new_search((string(pch)));
		    if(!new_search.is_found()) continue;
		    if(!new_search.is_new_word()) continue;
		    fout << string(pch) << endl;
		    int cnt = new_search.features_count();
            for(int i = 0;i<cnt;i++){
                feature now_feature = new_search.get_feature(i);
                fout << i << endl << now_feature.get_pos() << endl << now_feature.get_meaning() << endl;
            }
            fout << endl;
		    pch = strtok(NULL, " ,.-?!");
        }
	}
}
/**
 * @name best_first_search
 *
 * Find the best segmentation by doing a best first search of the
 * solution space.
 */
void Wordrec::best_first_search(CHUNKS_RECORD *chunks_record,
                                WERD_CHOICE *best_choice,
                                WERD_CHOICE *raw_choice,
                                STATE *state,
                                DANGERR *fixpt,
                                STATE *best_state) {
  SEARCH_RECORD *the_search;
  inT16 keep_going;
  STATE guided_state;   // not used

  num_joints = chunks_record->ratings->dimension() - 1;
  the_search = new_search(chunks_record, num_joints,
                          best_choice, raw_choice, state);

  // The default state is initialized as the best choice.  In order to apply
  // segmentation adjustment, or any other contextual processing in permute,
  // we give the best choice a poor rating to force the processed raw choice
  // to be promoted to best choice.
  the_search->best_choice->set_rating(100000.0);
  evaluate_state(chunks_record, the_search, fixpt);
  if (permute_debug) {
    tprintf("\n\n\n =========== BestFirstSearch ==============\n");
    best_choice->print("**Initial BestChoice**");
  }

#ifndef GRAPHICS_DISABLED
  save_best_state(chunks_record);
#endif
  start_recording();
  FLOAT32 worst_priority = 2.0f * prioritize_state(chunks_record, the_search);
  if (worst_priority < wordrec_worst_state)
    worst_priority = wordrec_worst_state;
  if (segment_debug) {
    print_state("BestFirstSearch", best_state, num_joints);
  }

  guided_state = *state;
  do {
                                 /* Look for answer */
    if (!hash_lookup (the_search->closed_states, the_search->this_state)) {

      if (tord_blob_skip) {
        free_state (the_search->this_state);
        break;
      }

      guided_state = *(the_search->this_state);
      keep_going = evaluate_state(chunks_record, the_search, fixpt);
      hash_add (the_search->closed_states, the_search->this_state);

      if (!keep_going ||
          (the_search->num_states > wordrec_num_seg_states) ||
          (tord_blob_skip)) {
        if (segment_debug)
          tprintf("Breaking best_first_search on keep_going %s numstates %d\n",
                  ((keep_going) ? "T" :"F"), the_search->num_states);
        free_state (the_search->this_state);
        break;
      }

      FLOAT32 new_worst_priority = 2.0f * prioritize_state(chunks_record,
                                                           the_search);
      if (new_worst_priority < worst_priority) {
        if (segment_debug)
          tprintf("Lowering WorstPriority %f --> %f\n",
                  worst_priority, new_worst_priority);
        // Tighten the threshold for admitting new paths as better search
        // candidates are found.  After lowering this threshold, we can safely
        // popout everything that is worse than this score also.
        worst_priority = new_worst_priority;
      }
      expand_node(worst_priority, chunks_record, the_search);
    }

    free_state (the_search->this_state);
    num_popped++;
    the_search->this_state = pop_queue (the_search->open_states);
    if (segment_debug && !the_search->this_state)
      tprintf("No more states to evalaute after %d evals", num_popped);
  }
  while (the_search->this_state);

  state->part1 = the_search->best_state->part1;
  state->part2 = the_search->best_state->part2;
  stop_recording();
  if (permute_debug) {
    tprintf("\n\n\n =========== BestFirstSearch ==============\n");
            // best_choice->debug_string(getDict().getUnicharset()).string());
    best_choice->print("**Final BestChoice**");
  }
  // save the best_state stats
  delete_search(the_search);
}