Example #1
0
void		req_broadcast(t_data *d, int fd, int fd_dir, char *cmd)
{
  int		i;
  char		*str;

  (void)fd_dir;
  i = 0;
  while (i < d->maxfd && i < d->max + 1)
    {
      d->fd[i].broad = Xmalloc(sizeof(t_broad));
      if (d->fd[i].type == FD_CLT && d->fd[i].status == CLT_IA && i != fd)
	{
	  check_short_way(d, fd, i);
	  str = str_fmt("message %d, %s\n",
			d->fd[i].broad->case_recep, erase_broad(cmd));
	  if (str)
	    {
	      printcs(d, i, str);
	      free(str);
	    }
	}
      free(d->fd[i].broad);
      ++i;
    }
  printcs(d, fd, "ok\n");
  broad_grc(d, fd, cmd);
}
Example #2
0
void srcfss(stack *st, value cur) {

	#ifdef TREEDOT
	st->id = count;
	printf("ID = %zu\n", st->id);
	if (st->id) fprintf(st->dot, "\t%zu -> %zu;\n", (st - 1)->id, st->id);
	printcs(st);
	#endif
	count++;

	if (cur < min) { min = cur; sol = *st; }

	#ifdef LIMIT
	if (!stop) {
		gettimeofday(&t2, NULL);
		if ((double)(t2.tv_usec - t1.tv_usec) / 1e6 + t2.tv_sec - t1.tv_sec > LIMIT) stop = true;
	}
	#ifndef COMPLETEFRONTIER
	else return;
	#endif
	#endif

	#ifdef BOUND
	const value b = bound(st);
	#ifdef LIMIT
	if (stop) { if (b < bou) bou = b; return; }
	else
	#endif
	if (b >= min - MINGAIN) return;
	#endif

	chunk tmp[C], rt[C];
	memcpy(tmp, st->c, sizeof(chunk) * C);
	MASKAND(tmp, st->r, tmp, C);
	edge popc = MASKPOPCNT(tmp, C);

	for (edge i = 0, e = MASKFFS(tmp, C); !stop && i < popc; i++, e = MASKCLEARANDFFS(tmp, e, C)) {

		agent v1 = X(st->a, e);
		agent v2 = Y(st->a, e);

		// At least one of the two coalitions must be a car
		if (!(st->dr[v1] + st->dr[v2])) continue;

		memcpy(rt, st->r, sizeof(chunk) * C);
		CLEAR(st->r, st->g[v1 * N + v2]);
		CLEAR(tmp, st->g[v1 * N + v2]);

		// Must not exceed the number of seats and the maximum number of drivers
		if (X(st->s, v1) + X(st->s, v2) > K || st->dr[v1] + st->dr[v2] > MAXDRIVERS) continue;

		CLEAR(st->c, st->g[v1 * N + v2]);
		st[1] = st[0];
		memcpy(st[1].r, rt, sizeof(chunk) * C);
		merge(st + 1, v1, v2);
		contract(st + 1, v1, v2);
		st[1].l[v1] = minpath(st[1].cs + Y(st[1].s, v1), X(st[1].s, v1), st[1].dr[v1], st->sp);
		srcfss(st + 1, cur + COST(v1, st[1].dr, st[1].l) - COST(v1, st->dr, st->l) - COST(v2, st->dr, st->l));
	}
}
Example #3
0
File: req_ebo.c Project: Ngob/Zappy
void		req_ebo(t_data *d, int fd, int fd_dir, char *cmd)
{
  char		res[BUFF_SIZE];

  (void)cmd;
  sprintf(res, "ebo %d\n", fd);
  printcs(d, fd_dir, res);
}
Example #4
0
File: req_ppo.c Project: Ngob/Zappy
void		req_ppo(t_data *d, int fd, int fd_dir, char *cmd)
{
  char		res[BUFF_SIZE];

  (void)cmd;
  sprintf(res, "ppo %d %d %d %d\n", fd, d->fd[fd].pos.pos_x,
	  d->fd[fd].pos.pos_y, d->fd[fd].pos.dir);
  printcs(d, fd_dir, res);
}
Example #5
0
void printcs(int len1, int len2)
{ 
  if(len1 == 0 || len2 == 0)return;
  if(dir[len1][len2] == 2)
  {
      printcs(len1-1, len2-1);
      printf("%c", str1[len1-1]);
  } 
  else {
    if(dir[len1][len2] == 0)
    {
      printcs(len1-1, len2);
    }
    else {
      printcs(len1, len2-1);
    }
  }
}
Example #6
0
void		req_droite(t_data *d, int fd, int fd_dir, char *cmd)
{
  int		i;

  i = 0;
  (void)cmd;
  (void)fd_dir;
  while (dir_tab_droite[i].cur_dir != -1)
    {
      if (dir_tab_droite[i].cur_dir == d->fd[fd].pos.dir)
	{
	  d->fd[fd].pos.dir = dir_tab_droite[i].next_dir;
	  printcs(d, fd_dir, "ok\n");
	  send_cmd(d, fd);
	  return ;
	}
      ++i;
    }
  printcs(d, fd_dir, "ko\n");
}
Example #7
0
File: req_ppo.c Project: Ngob/Zappy
void		req_ppo_drone(t_data *d, int fd, int fd_dir, char *cmd)
{
  t_drone	*dr;
  char		res[BUFF_SIZE];

  (void)cmd;
  dr = getDrone(d, fd);
  if (dr)
    {
      sprintf(res, "ppo %d %d %d %d\n", fd, dr->pos_x, dr->pos_y, dr->dir);
      printcs(d, fd_dir, res);
    }
}
Example #8
0
int main(int argc, char** argv)
{
  while(scanf("%s%s", str1, str2)==2)
  {
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    int ans = lcsl(len1,len2);
    printf("%d\n", ans);
    printcs(len1, len2);
    printf("\n");
  }
  return 0;
}
Example #9
0
File: req_pnw.c Project: Ngob/Zappy
void		req_pnw(t_data *d, int fd, int fd_dir, char *cmd)
{
  char		*res;

  (void)cmd;
  res = str_fmt("pnw %d %d %d %d %d %s\n", fd,
		d->fd[fd].pos.pos_x,
		d->fd[fd].pos.pos_y,
		d->fd[fd].pos.dir,
		d->fd[fd].lvl,
		d->fd[fd].team);
  if (res)
    {
      printcs(d, fd_dir, res);
      free(res);
    }
}
Example #10
0
int main(int argc, char *argv[]) {

	// Allocate stack

	stack st[N];

	// Create shortest paths matrix

	const unsigned seed = atoi(argv[1]);
	st->sp = createsp(seed);

	// Generate random set of drivers

	for (agent i = 0; i < D; i++)
		st->dr[i] = 1;

	memset(st->dr + D, 0, sizeof(agent) * (N - D));
	shuffle(st->dr, N, sizeof(agent));
	memcpy(drg, st->dr, N * sizeof(agent));

	// Initialise n, s, and cs data structures

	st->n[N] = N;

	for (agent i = 0; i < N; i++) {
		X(sg, i) = X(st->s, i) = 1;
		Y(sg, i) = Y(st->s, i) = csg[i] = st->cs[i] = i;
		st->l[i] = st->sp[4 * i * N + 2 * i + 1];
		min += COST(i, st->dr, st->l);
		st->n[st->n[i] = N + i + 1] = i;
	}

	// Initialise c and r bitmasks

	ONES(st->c, E + 1, C);
	CLEAR(st->c, 0);
	ONES(st->r, E + 1, C);
	CLEAR(st->r, 0);

	// Create graph

	#ifdef M
	init(seed);
	memset(st->g, 0, sizeof(edge) * N * N);
	scalefree(st->g, st->a);
	#else
	FILE *f = fopen(argv[2], "r");
	for (agent e = 1; e <= E; e++) {
		agent v1, v2;
		fscanf(f, "%u %u", &v1, &v2);
		createedge(st->g, st->a, v1, v2, e);
	}
	fclose(f);
	#endif

	// Reorder (eventually)

	#ifdef REORDER
	edge go[N * N] = {0};
	agent ao[2 * (E + 1)];
	#ifdef METIS
	idx_t options[METIS_NOPTIONS];
	METIS_SetDefaultOptions(options);
	options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT;
	options[METIS_OPTION_SEED] = seed;
	real_t tpwgts[2] = {0.5, 0.5}, ubvec = TOLERANCE;
	agent map[N];
	edge e = 1;
	for (agent i = 0; i < N; i++) map[i] = i;
	reorderedges(st->g, map, N, E, go, ao, &e, tpwgts, &ubvec, options);
	#else
	driversbfs(st->a, st->dr, go, ao);
	#endif
	memcpy(st->g, go, sizeof(edge) * N * N);
	memcpy(st->a, ao, sizeof(agent) * 2 * (E + 1));
	#endif

	#ifdef TREEDOT
	st->dot = fopen(TREEDOT, "w+");
	fprintf(st->dot, "digraph TREE {\n");
	fprintf(st->dot, "\tnode [color = none; shape = plaintext, width = 0.2, height = 0.2];\n");
	#endif

	// Solve

	sol = *st;
	#ifdef LIMIT
	value bou = bound(st);
	#endif
	gettimeofday(&t1, NULL);
	srcfss(st, min);
	gettimeofday(&t2, NULL);

	// Print solution

	#ifdef TREEDOT
	printf("SOLUTION = %zu\n", sol.id);
	fprintf(st->dot, "\t%zu [shape = circle, style = filled, fillcolor = green];\n", sol.id);
	#endif

	#ifdef PK
	FILE *pk = fopen(PK, "w+");
	fprintf(pk, "%u\n%u\n%u\n", N, K, seed);
	printg(st->g, pk);
	printpk(&sol, pk);
	fclose(pk);
	#endif

	#ifdef CSV
	printf("%u,%u,%s,%.2f,%f,%zu\n", N, E, argv[1], 0.01 * min, 
	       (double)(t2.tv_usec - t1.tv_usec) / 1e6 + t2.tv_sec - t1.tv_sec, count);
	#else
	printcs(&sol);
	printf("Visited nodes = %zu\n", count);
	printf("Elapsed time = %f\n", (double)(t2.tv_usec - t1.tv_usec) / 1e6 + t2.tv_sec - t1.tv_sec);
	printf("Solution = %.2f€\n", 0.01 * min);
	#ifdef LIMIT
	printf("Bound = %.2f€\n", 0.01 * bou);
	#endif
	#endif

	// Free data structures

	#ifdef TREEDOT
	fprintf(st->dot, "}");
	fclose(st->dot);
	#endif
	free(st->sp);

	return 0;
}