Example #1
0
File: ant.c Project: gpolo/QAP
QAP_solution_t *ant_build_solution(QAP_t *p){

    int i, j, lct, flt;
    set_t set_lct, set_flt; 
    QAP_solution_t *sol;

    sol = Malloc(sizeof(QAP_solution_t));

    set_init(&set_lct, p->size);
    set_init(&set_flt, p->size);

    /* flt: facility */
    for (i = 0; i < p->size; i++){
        lct = next_location(&set_lct);       
        flt = next_facility(p, &set_flt, lct);
        sol->perm[lct] = flt;
    }

    sol->cst = 0;
    for (i = 0; i < p->size; i++){
        for (j = i;  j < p->size; j++){
            sol->cst += p->dist[i][j] * p->flow[sol->perm[i]][sol->perm[j]];
            if (i != j){
                sol->cst += p->dist[j][i] * p->flow[sol->perm[j]][sol->perm[i]];
            }
        }
    }

    return sol;
}
Example #2
0
void RawLocation::change_register(Assembler::Register dst,
                                  Assembler::Register src) {
  GUARANTEE(!is_flushed() && in_register(), "Sanity");
  GUARANTEE(this->value() == src || 
            (is_two_word() && next_location()->value() == src), 
            "Only called if necessary");

  if (this->value() == src) { 
    this->set_value(dst);
  }
  if (is_two_word()) { 
    RawLocation *next = next_location();
    if (next->value() == src) { 
      next->set_value(dst);
    }
  }
}
Example #3
0
    bool
    Solver::find_location() {
	current_location.x = 0;
	current_location.y = 0;
	if (puzzle.get_board_square(current_location) == Board::blank)
	    return true;

	if (next_location())
	    return true;

	return false;
    }
Example #4
0
    bool
    Solver::locate_piece() {
	const Piece &current_piece = puzzle.get_piece(current_piece_index);
	Location location = current_location
	    - current_piece.get_square(0, current_direction);

	if (!puzzle.locate_piece(current_piece_index, location,
		current_direction))
	    return false;

	located_piece_indice.push_back(current_piece_index);
	if (located_piece_indice.size() == puzzle.get_piece_count())
	    return true;

	current_direction = right0;
	current_piece_index = 0;
	while (current_piece_index < puzzle.get_piece_count()) {
	    if (!puzzle.is_located_piece(current_piece_index))
		break;
	    current_piece_index++;
	}

	return next_location();
    }
Example #5
0
 bool uses_register( const Assembler::Register reg ) const {
   return get_register() == reg ||
          ( is_two_word() && next_location()->get_register() == reg );
 }
Example #6
0
void predict_all(DATA **data) {
	int i = 0, random_path = 0;
	DPOINT *here = NULL, *where = NULL;
	PRED_AT at_what;
	unsigned int row, col;

	n_done = 0;
	val_data = get_dataval();
	if (val_data->id > -1) {
		at_what = AT_POINTS;
		n_pred_locs = val_data->n_list;
		if (val_data->colns)
			strata_min = val_data->minstratum;
	} else if (get_n_masks() > 0) {
		at_what = AT_GRIDMAP;
		here = (DPOINT *) emalloc(sizeof(DPOINT));
		here->u.stratum = -2; /* only NON-MV cells */
		if (max_block_dimension(0) > 0.0)
			SET_BLOCK(here);
		else
			SET_POINT(here);
	} else /* what else ? */
		return;

	if (at_what == AT_GRIDMAP && get_n_outfile() == 0) {
		pr_warning("no output maps defined");
		return;
	}

	init_predictions(at_what);

	if (at_what == AT_GRIDMAP && !data[0]->dummy) { 
		if (data[0]->maxX < masks[0]->x_ul ||
				data[0]->minX > (masks[0]->x_ul + masks[0]->cols * masks[0]->cellsizex) ||
				data[0]->minY > masks[0]->y_ul ||
				data[0]->maxY < (masks[0]->y_ul - masks[0]->rows * masks[0]->cellsizey)) {
			pr_warning("ALL data are outside the map boundaries");
			printlog("data x[%g,%g], y[%g,%g]; map x[%g,%g], y[%g,%g]\n",
				data[0]->minX, data[0]->maxX, data[0]->minY, data[0]->maxY,
				masks[0]->x_ul,
				masks[0]->x_ul + masks[0]->cols * masks[0]->cellsizex,
				masks[0]->y_ul - masks[0]->rows * masks[0]->cellsizey,
				masks[0]->y_ul
				);
		}
		else if (map_xy2rowcol(masks[0], data[0]->minX, data[0]->minY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->maxX, data[0]->minY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->minX, data[0]->maxY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->maxX, data[0]->maxY, &row, &col))
			pr_warning("at least some data are outside the map boundaries");
			/* this is not a sufficient test! */
	}

	if (gl_rp) /* Yes, by default */
		random_path = is_simulation(get_method());
	row = col = 0;
	while ((where = next_location(here, at_what, random_path,
			&row, &col, data)) != NULL) {
		for (i = 0; i < get_n_outfile(); i++)
			set_mv_double(&(est[i])); /* initialize estimates */
		if (where->u.stratum >= 0) {
			if (get_mode() != STRATIFY) {
				for (i = 0; i < get_n_vars(); i++)
					select_at(data[i], where);
			} else if (where->u.stratum < get_n_vars())
				select_at(data[where->u.stratum], where);
			get_est(data, get_method(), where, est);
		}
		/* printf("%g %g\n", est[0], est[1]); */
		write_output(est, at_what, where, row, col);
	}
	exit_predictions(at_what);
	if (here != NULL)
		efree(here);
	print_progress(100, 100);
}