コード例 #1
0
ファイル: tm_mapping.c プロジェクト: davidheryanto/sc14
void display_other_heuristics(tm_topology_t *topology,int N,double **comm,double **arch){
  CLOCK_T time1,time0;
  double duration; 
  int *sol;
 
  sol=(int*)malloc(sizeof(int)*N);

  map_Packed(topology,N,sol);
  printf("Packed: "); 
  print_sol(N,sol,comm,arch);



  map_RR(N,sol);
  printf("RR: "); 
  print_sol(N,sol,comm,arch);

  CLOCK(time0);
  map_MPIPP(topology,1,N,sol,comm,arch);
  CLOCK(time1);
  duration=CLOCK_DIFF(time1,time0);
  printf("MPIPP-1-D:%f\n",duration);
  printf("MPIPP-1: ");
  print_sol(N,sol,comm,arch);

  CLOCK(time0);
  map_MPIPP(topology,5,N,sol,comm,arch);
  CLOCK(time1);
  duration=CLOCK_DIFF(time1,time0);
  printf("MPIPP-5-D:%f\n",duration);
  printf("MPIPP-5: ");
  print_sol(N,sol,comm,arch);

  free(sol);
}
コード例 #2
0
void nqueens()
{
	int i,k;
	k=1;
	x[k]=0;
	while(k!=0)
	{
		x[k]+=1;
		while(x[k]<=n && (!place(x,k)))
			x[k]+=1;
		if(x[k]<=n)
		{
			if(k==n)
			{
				cnt++;
				printf("Solution %d is\n",cnt);
				print_sol();
			}
			else
			{
				k++;
				x[k]=0;
			}
		}
		else
		{
			x[k]=0;
			k--;
		}
	}
}
コード例 #3
0
int queen(int n)
{
 int k=0;
 a[k]=0;
 while(k<n+1)
 {
  a[k]=a[k]+1;
  while((a[k]<=n)&&!place(k)){
   a[k]++;}
  if(a[k]<=n)
  {
   if(k==n){
    print_sol(n);
    return 0;}
   else
   {
    k++;
    a[k]=0;
   }
  }
  else{
   k--;
 }
}
printf("sad");
}
コード例 #4
0
ファイル: tm_mapping.c プロジェクト: 00datman/ompi
void display_other_heuristics(tm_topology_t *topology,int N,double **comm,int TGT_flag, int *constraints, double *cost)
{
  int *sol = NULL;

  sol = (int*)MALLOC(sizeof(int)*N);

  map_Packed(topology,N,sol);
  printf("Packed: ");
  if (TGT_flag == 1)
    print_sol_inv(N,sol,comm,cost, topology);
  else
    print_sol(N,sol,comm,cost, topology);

  map_RR(N,sol,constraints);
  printf("RR: ");
  if (TGT_flag == 1)
    print_sol_inv(N,sol,comm, cost, topology);
  else
    print_sol(N,sol,comm, cost, topology);

/*   double duration; */
/*   CLOCK_T time1,time0; */
/*   CLOCK(time0); */
/*   map_MPIPP(topology,1,N,sol,comm,arch); */
/*   CLOCK(time1); */
/*   duration=CLOCK_DIFF(time1,time0); */
/*   printf("MPIPP-1-D:%f\n",duration); */
/*   printf("MPIPP-1: "); */
/*   if (TGT_flag == 1)  */
/*     print_sol_inv(N,sol,comm,arch); */
/*   else */
/*   print_sol(N,sol,comm,arch); */

/*   CLOCK(time0); */
/*   map_MPIPP(topology,5,N,sol,comm,arch); */
/*   CLOCK(time1); */
/*   duration=CLOCK_DIFF(time1,time0); */
/*   printf("MPIPP-5-D:%f\n",duration); */
/*   printf("MPIPP-5: "); */
/*   if (TGT_flag == 1)  */
/*     print_sol_inv(N,sol,comm,arch); */
/*   else */
/*   print_sol(N,sol,comm,arch); */

  FREE(sol);
}
コード例 #5
0
ファイル: dreal_jl_01.c プロジェクト: 4lex4nder/dreal3
int main(int argc, char * argv[]) {
    // Creating context
    fprintf(stderr, "Creating context\n");
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    // Setting verbosity
    opensmt_set_verbosity(ctx, 4);

    // Creating integer variables
    fprintf(stderr, "Creating some integer variables\n");
    opensmt_expr x = opensmt_mk_int_var(ctx, "x" , -10, 10);
    opensmt_expr y = opensmt_mk_int_var(ctx, "y" , -10, 10);

    // numbers -- 2, 7, 10
    opensmt_expr num2  = opensmt_mk_num_from_string(ctx, "2");
    opensmt_expr num7  = opensmt_mk_num_from_string(ctx, "7");
    opensmt_expr num10 = opensmt_mk_num_from_string(ctx, "10");

    // t1 = x > 2
    opensmt_expr t1 = opensmt_mk_gt(ctx, x, num2);
    
    // t2 = y < 10
    opensmt_expr t2 = opensmt_mk_lt(ctx, y, num10);


    // t3 = 2 * y
    opensmt_expr subarray1[2] = {num2, y};
    opensmt_expr t3 = opensmt_mk_times(ctx, subarray1, 2);

    // t4 = x + t3 == 7
    opensmt_expr subarray2[2] = {x, t3};
    opensmt_expr t4 = opensmt_mk_eq(ctx, opensmt_mk_plus(ctx, subarray2, 2), num7);

    // t5 = t1 /\ t2 /\ t4
    opensmt_expr subarray3[3] = {t1, t2, t4};
    opensmt_expr t5 = opensmt_mk_and(ctx, subarray3, 3);

    opensmt_assert(ctx, t5);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y);
    }

    // Resetting context
    fprintf(stderr, "Resetting context\n");
    opensmt_reset(ctx);
    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}
コード例 #6
0
ファイル: simulator.cpp プロジェクト: bezout/libhelico
  std::string to_string(size_t debut, size_t fin)
  {
    std::vector<std::string> img(height,std::string(fin - debut + 1,' ')+"\n");

    print_sol(img, debut, fin);
    for(auto& fish : fishes)
      print_fish(img, fish, debut, fin);
    
    return std::accumulate(img.rbegin(),img.rend(),std::string(),std::plus<std::string>{});
  }
コード例 #7
0
ファイル: queens.c プロジェクト: aparajitamehta/repo1
void Place_Queen(int i) {
	for (Q[i] = 1; Q[i] <= N; Q[i]++) {
		if (Queen_Status(i) == not_attacked) {
			if (i == N) {
				print_sol();
				exit(1); //stop as soon as a sol. is found.
			} else {
				Place_Queen(i+1);
			}
		}
	}
	return; //control returns back to main or Place_Queen(i-1);
}
コード例 #8
0
ファイル: knr_5_20.c プロジェクト: danadorneanu/portofolio
void dcl(void)
{
   int ns;
   for (ns = 0; gettoken() == '*'; ) /* count *'s */
      ns++;
   /* doing smthing fishy */
   if(tokentype == '(')
   {
      print_sol();
      dirdcl();
   }
   
   dirdcl();
   while (ns-- > 0)
      strcat(out, " pointer to");
}
コード例 #9
0
ファイル: ea_02.c プロジェクト: dpsanders/dreal3-1
int main() {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_set_precision (ctx, 0.001);

    // Creating Exist Real variables
    opensmt_expr x = opensmt_mk_real_var(ctx, "x" , 0, 8);
    // Creating Forall Real variables
    opensmt_expr y = opensmt_mk_forall_real_var(ctx, "y" , 0, 8.0);

    // constants
    opensmt_expr two = opensmt_mk_num(ctx, 2.0);
    opensmt_expr five = opensmt_mk_num(ctx, 5.0);
    opensmt_expr nine = opensmt_mk_num(ctx, 9.0);

    // circle1 := (x-2)^2 + (y-2)^2 <= 9
    opensmt_expr circle1 =
        opensmt_mk_leq(ctx,
                       opensmt_mk_plus_2(ctx,
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, x, two), two),
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, y, two), two)),
                       nine);
    // circle2 := (x-5)^2 + (y-5)^2 <= 9
    opensmt_expr circle2 =
        opensmt_mk_leq(ctx,
                       opensmt_mk_plus_2(ctx,
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, x, five), two),
                                         opensmt_mk_pow(ctx, opensmt_mk_minus(ctx, y, five), two)),
                       nine);

    opensmt_expr vars[] = {y};
    opensmt_expr formula = opensmt_mk_forall(ctx, vars, 1,
                                             opensmt_mk_or_2(ctx, circle1, circle2));

    opensmt_assert(ctx, formula);
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, "x", x);
    }

    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}
コード例 #10
0
ファイル: dreal_jl_02.c プロジェクト: 4lex4nder/dreal3
int main(int argc, char * argv[]) {
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);
    opensmt_expr x = opensmt_mk_real_var(ctx, "x" , 0.0, 1.0);
    opensmt_expr y = opensmt_mk_real_var(ctx, "y" , 0.0, 1.0);
    opensmt_expr ite = opensmt_mk_ite(ctx, opensmt_mk_gt(ctx, x, opensmt_mk_num(ctx, 0.4)),
                                      opensmt_mk_num(ctx, 0.3),
                                      opensmt_mk_num(ctx, 0.4));
    opensmt_expr eq = opensmt_mk_eq(ctx, y, ite);
    opensmt_assert( ctx, eq);
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y);
    }
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);
    return 0;
}
コード例 #11
0
void queen(int n){
	int k=1;
	a[k]=0;
	while(k!=0){
		a[k]=a[k]+1;
		while((a[k]<=n)&&!place(k))
			a[k]++;
		if(a[k]<=n){
			if(k==n)
				print_sol(n);
			else{
				k++;
				a[k]=0;
			}
		}
		else
		k--;
	}
}
コード例 #12
0
ファイル: knights_tour.c プロジェクト: GPrabhudas/Algorithms
void solveKT(){
    int sol[N][N];
    int i,j;
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            sol[i][j]=-1;
        }
    }
    int x_move[N]={2,1,-1,-2,-2,-1,1,2};
    int y_move[N]={1,2,2,1,-1,-2,-2,-1};
    sol[0][0]=0;
    if(solveKTUtil(0,0,1,sol,x_move,y_move)== false){
        printf("Solution not Possible\n");
    }
    else
    {
        print_sol(sol);
    }
}
コード例 #13
0
ファイル: knr_5_20.c プロジェクト: danadorneanu/portofolio
/* dirdcl: parse a direct declarator */
void dirdcl(void)
{
   int type;
   if (tokentype == '\n')
      ;
   else if (tokentype == ',')
   {
      print_sol();
   }
   else if (tokentype == '(') 
   { 
      /* ( dcl ) */
      if(!param_no)
      {
         dcl();
         if (tokentype != ')')
            printf("error: missing )\n");
      }
   } 
   else if (tokentype == NAME) 
      /* variable name */
      strcpy(name, token);
   else if (tokentype == ')')
      ;
   else
   {
      printf("\n tmp: the tokentype is %d \n", tokentype);
      printf("error: expected name or (dcl)\n");
   }

   while ((type=gettoken()) == PARENS || type == BRACKETS)     
      if (type == PARENS || param_no)
         strcat(out, " function returning");
      else 
      {
         strcat(out, " array");
         strcat(out, token);
         strcat(out, " of");
      }
   if (param_no)
         strcat(out, " function returning");
}
コード例 #14
0
ファイル: Daenerys.c プロジェクト: Einath/AProg_Practices
void back(int distancia[PLACES+1][PLACES+1], int RnU[PLACES][COL], int visited[PLACES+2], int variante, solution_step sol[PLACES+2], int step){ 
  printf("== Backtracking | Variante %d ==\n", variante);   
  /*
   * Expansión
   * Solución
   * Fallo
   * Nodos:
   * - Solución
   * - Problema
   * - Fracaso
   */
  int current;
  int i=1; 

  visited[CAMP] = RESERVED; 

 
  // while(complete(visited)==FALSE){
  for(i=1; i<=PLACES; i++){
    current = sol[i-1].position; 
    
    if(visited[i]==FALSE){ // objetivo
      calc(RnU, distancia, sol, current, i, step);
      visited[i]=TRUE; 
      back(distancia, RnU, visited, variante, sol, step+1); 
      if((sol[i].balance <0)){ // Deshacer
	visited[i]=FALSE; 
      }
    }
    //  i++; 
  }

  current = sol[PLACES].position; 
  calc(RnU, distancia, sol, current, CAMP, PLACES+1); 
  
  print_sol(sol); 

}
コード例 #15
0
ファイル: knr_5_20.c プロジェクト: danadorneanu/portofolio
int  main(void) /* convert declaration to words */
{
   int i = 0;
   int ret = 0;

   while (gettoken() != EOF) 
   {
//      if (tokentype != '\n')
  //       printf("syntax error\n");
      for (i = 0; i < tab_no; i++)
         printf("\t");
      if (name[0] && datatype[0])
         printf("%s: %s %s\n", name, out, datatype);

      strcpy(datatype, token); 
      out[0] = '\0';
      name[0] = '\0';
      dcl();        
      print_sol();
   }

   return ret;
}
コード例 #16
0
ファイル: Daenerys.c プロジェクト: Einath/AProg_Practices
void voraz(int distancia[PLACES+1][PLACES+1], int RnU[PLACES][COL], int visited[PLACES+2], int variante, solution_step sol[PLACES+2]){ 
  int i; 
  printf("== Algoritmo Voraz | Variante %d ==\n", variante); 
  int destination, current; 
  /*
   * calc(RnU, distancia, sol, CAMP, ASTAPOR, 1); 
   * calc(RnU, distancia, sol, ASTAPOR, BHORASH, 2); 
   * calc(RnU, distancia, sol, BHORASH, YUNKAI, 3); 
   * calc(RnU, distancia, sol, YUNKAI, MEEREEN, 4); 
   * calc(RnU, distancia, sol, MEEREEN, CAMP, 5); 
   * !!Brassard 13.1.2 - 13.2.3 pp. 266 trp
   */


  visited[CAMP] = RESERVED; 

  i=1; 
  while(complete(visited)==FALSE){
    current = sol[i-1].position; 

    /* --------------------------- selección de variante */
    if((variante == 1) || (variante == 2))
      destination = selection_var1(RnU, distancia, visited, sol[i-1].position);
    else
      printf("No implementado\n"); 
    /* ------------------------fin selección de variante */

    calc(RnU, distancia, sol, current, destination, i); 
    visited[destination]=TRUE; 
    i++; 
  }

  current = sol[PLACES].position; 
  calc(RnU, distancia, sol, current, CAMP, PLACES+1); 

  print_sol(sol); 
}
コード例 #17
0
ファイル: example_01.c プロジェクト: dpsanders/dreal3-1
int main(int argc, char * argv[]) {
    // Creating context
    fprintf(stderr, "Creating context\n");
    opensmt_init();
    opensmt_context ctx = opensmt_mk_context(qf_nra);

    // Setting verbosity
    opensmt_set_verbosity(ctx, 4);

    // Creating boolean variables
    fprintf(stderr, "Creating some boolean variables\n");
    opensmt_expr a = opensmt_mk_bool_var(ctx, "a");
    opensmt_expr b = opensmt_mk_bool_var(ctx, "b");
    opensmt_expr c = opensmt_mk_bool_var(ctx, "c");
    // Creating integer variables
    fprintf(stderr, "Creating some integer variables\n");
    opensmt_expr x = opensmt_mk_int_var(ctx, "x" , -10, 10);
    opensmt_expr y = opensmt_mk_int_var(ctx, "y" , -10, 10);
    opensmt_expr z = opensmt_mk_int_var(ctx, "z" , -10, 10);
    // Creating inequality
    fprintf(stderr, "Creating x - y <= 0\n");

    fprintf(stderr, "  Creating x - y\n");
    opensmt_expr minus = opensmt_mk_minus(ctx, x, y);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(minus);
    fprintf(stderr, "\n");

    fprintf(stderr, "  Creating 0\n");
    opensmt_expr zero = opensmt_mk_num_from_string(ctx, "0");
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(zero);
    fprintf(stderr, "\n");

    fprintf(stderr, "  Creating x - y <= 0\n");
    opensmt_expr leq = opensmt_mk_leq(ctx, minus, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq);
    fprintf(stderr, "\n");

    // Creating inequality 2
    fprintf(stderr, "Creating y - z <= 0\n");
    opensmt_expr minus2 = opensmt_mk_minus(ctx, y, z);
    opensmt_expr leq2 = opensmt_mk_leq(ctx, minus2, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq2);
    fprintf(stderr, "\n");

    // Creating inequality 3
    fprintf(stderr, "Creating z - x <= -1\n");
    opensmt_expr minus3 = opensmt_mk_minus(ctx, z, x);
    opensmt_expr mone = opensmt_mk_num_from_string(ctx, "-1");
    opensmt_expr leq3 = opensmt_mk_leq(ctx, minus3, mone);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq3);
    fprintf(stderr, "\n");

    // Creating inequality 4
    fprintf(stderr, "Creating z - x <= 0\n");
    opensmt_expr minus4 = opensmt_mk_minus(ctx, z, x);
    opensmt_expr leq4 = opensmt_mk_leq(ctx, minus4, zero);
    fprintf(stderr, "  Expression created: ");
    opensmt_print_expr(leq4);
    fprintf(stderr, "\n");

    // Asserting first inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq);
    opensmt_push(ctx);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    opensmt_result res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Asserting second inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq2);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq2);
    opensmt_push(ctx);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Asserting third inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq3);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq3);
    opensmt_push(ctx);

    // Checking for consistency - it is UNSAT
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Backtracking one step - so the state is SAT again
    opensmt_pop(ctx);
    fprintf(stderr, "Backtracking one step\n\n");

    // Asserting fourth inequality
    fprintf(stderr, "Asserting ");
    opensmt_print_expr(leq4);
    fprintf(stderr, "\n");
    opensmt_assert(ctx, leq4);

    // Checking for consistency
    fprintf(stderr, "\nChecking for consistency: ");
    res = opensmt_check(ctx);
    fprintf(stderr, "%s\n\n", res == l_false ? "unsat" : "sat");
    if (res == l_true) {
        print_sol(ctx, x, y, z);
    }

    // Resetting context
    fprintf(stderr, "Resetting context\n");
    opensmt_reset(ctx);
    // Deleting context
    fprintf(stderr, "Deleting context\n");
    opensmt_del_context(ctx);

    return 0;
}