int main(int argc, char **argv) { int height; int width; t_maze **maze; if (argc < 4) { printf("usage: ./generator [height] [width] [name]\n"); return (0); } height = atoi(argv[1]); width = atoi(argv[2]); if (width < 5 || height < 5) { my_printf("values must be > 5\n"); return (0); } srand(time(NULL)); maze = pre_generator(height, width); generator(maze, height, width); imperfect_gen(height, width, maze); if ((height % 2) == 0 || (width % 2) == 0) add_solution(maze, height, width); if (write_maze_to_file(maze, argv[3], width) == -1) return (-1); return (0); }
int put_queen_brute(int nb_queen, char board[8][8], int possibility, solution **s, options *op) { int posy = 0; int posx = 0; for (; posy < 8; ++posy) { for (posx = 0; posx < 8; ++posx) { if (!board[posy][posx]) { set_queen(nb_queen, board, posx, posy); if (nb_queen == 8) { if (add_solution(board, s)) { possibility += 1; print_board(board, possibility, op); if (possibility == 92 && op->stop_before_end) op->end = 1; } } else possibility = put_queen_brute(nb_queen + 1, board, possibility, s, op); unset_queen(nb_queen, board); if (op->end) return possibility; } } } return possibility; }
void ColumnMajorMatrixTest::addMatrixScalar() { ColumnMajorMatrix add_solution(3, 3); add_solution(0, 0) = 11; add_solution(1, 0) = 12; add_solution(2, 0) = 13; add_solution(0, 1) = 14; add_solution(1, 1) = 15; add_solution(2, 1) = 16; add_solution(0, 2) = 17; add_solution(1, 2) = 18; add_solution(2, 2) = 19; CPPUNIT_ASSERT(add_solution == *a + 10); }
/* ---------------------------------------------------------------------- */ int add_mix (struct mix *mix_ptr) /* ---------------------------------------------------------------------- */ { /* * calls add_solution to accumulate all data in master->totals * and other variables. */ int i; int n; LDBLE sum_fractions, intensive, extensive; struct solution *solution_ptr; int count_positive; LDBLE sum_positive; if (mix_ptr == NULL) return (OK); if (mix_ptr->count_comps <= 0) return (OK); sum_fractions = 0.0; sum_positive = 0.0; count_positive = 0; for (i = 0; i < mix_ptr->count_comps; i++) { sum_fractions += mix_ptr->comps[i].fraction; if (mix_ptr->comps[i].fraction > 0) { sum_positive += mix_ptr->comps[i].fraction; count_positive++; } } for (i = 0; i < mix_ptr->count_comps; i++) { solution_ptr = solution_bsearch (mix_ptr->comps[i].n_solution, &n, TRUE); if (solution_ptr == NULL) { input_error++; continue; } extensive = mix_ptr->comps[i].fraction; intensive = extensive / sum_fractions; if (count_positive < mix_ptr->count_comps) { if (mix_ptr->comps[i].fraction > 0) { intensive = extensive / sum_positive; } else { intensive = 0; } } add_solution (solution_ptr, extensive, intensive); } return (OK); }
void ColumnMajorMatrixTest::addMatrixScalarEquals() { ColumnMajorMatrix add_solution(3, 3); add_solution(0, 0) = 11; add_solution(1, 0) = 12; add_solution(2, 0) = 13; add_solution(0, 1) = 14; add_solution(1, 1) = 15; add_solution(2, 1) = 16; add_solution(0, 2) = 17; add_solution(1, 2) = 18; add_solution(2, 2) = 19; // Scalar add and update *a += 10; CPPUNIT_ASSERT(add_solution == *a); }
void align(){ int k, i, j, match, last_match = NEG_INF, r, s, t; if( M==N ){ // possible solution with no indels printf("%d %d\n", R1[M][N], 0); last_match = R1[M][N]; } for( k = 1; k <= K; ++k ){ init_base_cases(k); for( i = 1; i <= M; ++i ){ for( j = 1; j <= N; ++j ){ match = seq1[i-1] == seq2[j-1]; // do not allow the value of 'match' to make it possible from NEG_INF r = R2[i-1][j-1] + match *(R2[i-1][j-1]!=NEG_INF); s = S2[i-1][j-1] + match *(S2[i-1][j-1]!=NEG_INF); t = T2[i-1][j-1] + match *(T2[i-1][j-1]!=NEG_INF); R2[i][j] = max( r, s, t ); S2[i][j] = max( R1[i][j-1], S2[i][j-1], T1[i][j-1] ); T2[i][j] = max( R1[i-1][j], S1[i-1][j], T2[i-1][j] ); } } // add to the solution set add_solution( &last_match , k); swap_tables( &R1, &R2 ); swap_tables( &S1, &S2 ); swap_tables( &T1, &T2 ); } fclose(f_out); }
/* ---------------------------------------------------------------------- */ int P_step (LDBLE step_fraction) /* ---------------------------------------------------------------------- */ { /* * zero global solution, add solution or mixture, add exchange, * add surface, add gas phase, add solid solutions, * set temperature, and add reaction. * Ensure all elements * included in any of these are present in small amounts. * Save result as n_user -1. */ LDBLE difftemp; int step_number; struct pp_assemblage *pp_assemblage_save = NULL; struct s_s_assemblage *s_s_assemblage_save = NULL; if (svnid == NULL) fprintf (stderr, " "); /* * Zero out global solution data */ xsolution_zero (); /* * Set reaction to zero */ step_x = 0.0; step_number = reaction_step; /* * Mixing or solution */ if (use.mix_ptr != NULL) { add_mix (use.mix_ptr); } else if (use.solution_ptr != NULL) { add_solution (use.solution_ptr, 1.0, 1.0); } else { input_error++; error_msg ("Neither mixing nor an initial solution have " "been defined in reaction step.", STOP); } /* * Reaction */ if (use.irrev_ptr != NULL) { add_reaction (use.irrev_ptr, step_number, step_fraction); } /* * Kinetics */ if (use.kinetics_ptr != NULL) { add_kinetics (use.kinetics_ptr); /* master_ptr =master_bsearch("S(6)"); output_msg(OUTPUT_MESSAGE,"Added kinetics, S(6) %e\n", master_ptr->total); master_ptr =master_bsearch("S"); output_msg(OUTPUT_MESSAGE,"Added kinetics, S %e\n", master_ptr->total); */ } /* * Exchange */ if (use.exchange_ptr != NULL) { add_exchange (use.exchange_ptr); } /* * Surface */ if (use.surface_ptr != NULL) { add_surface (use.surface_ptr); } /* * Gases */ if (use.gas_phase_ptr != NULL) { add_gas_phase (use.gas_phase_ptr); } /* * Temperature */ if (use.temperature_ptr != NULL) { add_temperature (use.temperature_ptr, step_number); } if ((state == TRANSPORT) && (transport_step != 0) && (cell > 0) && (cell != count_cells + 1)) { difftemp = tc_x - cell_data[cell - 1].temp; cell_data[cell - 1].temp += difftemp / tempr; tc_x = cell_data[cell - 1].temp; } /* * Pure phases and solid solutions are added to avoid * zero or negative concentrations */ /* * Pure phases */ if (use.pp_assemblage_ptr != NULL) { pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc (sizeof (struct pp_assemblage)); if (pp_assemblage_save == NULL) malloc_error (); pp_assemblage_copy (use.pp_assemblage_ptr, pp_assemblage_save, use.pp_assemblage_ptr->n_user); add_pp_assemblage (use.pp_assemblage_ptr); } /* * Solid solutions */ if (use.s_s_assemblage_ptr != NULL) { s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc (sizeof (struct s_s_assemblage)); if (s_s_assemblage_save == NULL) malloc_error (); s_s_assemblage_copy (use.s_s_assemblage_ptr, s_s_assemblage_save, use.s_s_assemblage_ptr->n_user); add_s_s_assemblage (use.s_s_assemblage_ptr); } /* * Check that elements are available for gas components, * pure phases, and solid solutions */ if (use.gas_phase_ptr != NULL) { gas_phase_check (use.gas_phase_ptr); } if (use.pp_assemblage_ptr != NULL) { pp_assemblage_check (use.pp_assemblage_ptr); } if (use.s_s_assemblage_ptr != NULL) { s_s_assemblage_check (use.s_s_assemblage_ptr); } /* * Check that element moles are >= zero */ if (solution_check () == MASS_BALANCE) { /* reset moles and deltas */ if (use.pp_assemblage_ptr != NULL) { pp_assemblage_free (use.pp_assemblage_ptr); pp_assemblage_copy (pp_assemblage_save, use.pp_assemblage_ptr, use.pp_assemblage_ptr->n_user); pp_assemblage_free (pp_assemblage_save); pp_assemblage_save = (struct pp_assemblage *) free_check_null (pp_assemblage_save); } if (use.s_s_assemblage_ptr != NULL) { s_s_assemblage_free (use.s_s_assemblage_ptr); s_s_assemblage_copy (s_s_assemblage_save, use.s_s_assemblage_ptr, use.s_s_assemblage_ptr->n_user); s_s_assemblage_free (s_s_assemblage_save); s_s_assemblage_save = (struct s_s_assemblage *) free_check_null (s_s_assemblage_save); } return (MASS_BALANCE); } /* * Copy global into solution n_user = -1 */ xsolution_save (-1); step_save_surf (-1); step_save_exch (-1); /* * Clean up temporary space */ if (pp_assemblage_save != NULL) { pp_assemblage_free (pp_assemblage_save); pp_assemblage_save = (struct pp_assemblage *) free_check_null (pp_assemblage_save); } if (s_s_assemblage_save != NULL) { s_s_assemblage_free (s_s_assemblage_save); s_s_assemblage_save = (struct s_s_assemblage *) free_check_null (s_s_assemblage_save); } return (OK); }
/* Look for all integer points in "bset", which is assumed to be bounded, * and call callback->add on each of them. * * We first compute a reduced basis for the set and then scan * the set in the directions of this basis. * We basically perform a depth first search, where in each level i * we compute the range in the i-th basis vector direction, given * fixed values in the directions of the previous basis vector. * We then add an equality to the tableau fixing the value in the * direction of the current basis vector to each value in the range * in turn and then continue to the next level. * * The search is implemented iteratively. "level" identifies the current * basis vector. "init" is true if we want the first value at the current * level and false if we want the next value. * Solutions are added in the leaves of the search tree, i.e., after * we have fixed a value in each direction of the basis. */ int isl_basic_set_scan(struct isl_basic_set *bset, struct isl_scan_callback *callback) { unsigned dim; struct isl_mat *B = NULL; struct isl_tab *tab = NULL; struct isl_vec *min; struct isl_vec *max; struct isl_tab_undo **snap; int level; int init; enum isl_lp_result res; if (!bset) return -1; dim = isl_basic_set_total_dim(bset); if (dim == 0) return scan_0D(bset, callback); min = isl_vec_alloc(bset->ctx, dim); max = isl_vec_alloc(bset->ctx, dim); snap = isl_alloc_array(bset->ctx, struct isl_tab_undo *, dim); if (!min || !max || !snap) goto error; tab = isl_tab_from_basic_set(bset, 0); if (!tab) goto error; if (isl_tab_extend_cons(tab, dim + 1) < 0) goto error; tab->basis = isl_mat_identity(bset->ctx, 1 + dim); if (1) tab = isl_tab_compute_reduced_basis(tab); if (!tab) goto error; B = isl_mat_copy(tab->basis); if (!B) goto error; level = 0; init = 1; while (level >= 0) { int empty = 0; if (init) { res = isl_tab_min(tab, B->row[1 + level], bset->ctx->one, &min->el[level], NULL, 0); if (res == isl_lp_empty) empty = 1; if (res == isl_lp_error || res == isl_lp_unbounded) goto error; isl_seq_neg(B->row[1 + level] + 1, B->row[1 + level] + 1, dim); res = isl_tab_min(tab, B->row[1 + level], bset->ctx->one, &max->el[level], NULL, 0); isl_seq_neg(B->row[1 + level] + 1, B->row[1 + level] + 1, dim); isl_int_neg(max->el[level], max->el[level]); if (res == isl_lp_empty) empty = 1; if (res == isl_lp_error || res == isl_lp_unbounded) goto error; snap[level] = isl_tab_snap(tab); } else isl_int_add_ui(min->el[level], min->el[level], 1); if (empty || isl_int_gt(min->el[level], max->el[level])) { level--; init = 0; if (level >= 0) if (isl_tab_rollback(tab, snap[level]) < 0) goto error; continue; } if (level == dim - 1 && callback->add == increment_counter) { if (increment_range(callback, min->el[level], max->el[level])) goto error; level--; init = 0; if (level >= 0) if (isl_tab_rollback(tab, snap[level]) < 0) goto error; continue; } isl_int_neg(B->row[1 + level][0], min->el[level]); if (isl_tab_add_valid_eq(tab, B->row[1 + level]) < 0) goto error; isl_int_set_si(B->row[1 + level][0], 0); if (level < dim - 1) { ++level; init = 1; continue; } if (add_solution(tab, callback) < 0) goto error; init = 0; if (isl_tab_rollback(tab, snap[level]) < 0) goto error; } isl_tab_free(tab); free(snap); isl_vec_free(min); isl_vec_free(max); isl_basic_set_free(bset); isl_mat_free(B); return 0; error: isl_tab_free(tab); free(snap); isl_vec_free(min); isl_vec_free(max); isl_basic_set_free(bset); isl_mat_free(B); return -1; }