Ejemplo n.º 1
0
int main(int argc, char **argv)
{
	int c_smenu, rotatefan, mouserotate, sofatranslate, scalecompound, viewtype, housewall, lightsonoff;
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(500, 500);
	glutCreateWindow("3D HOUSE");
	initfirst();
	glutDisplayFunc(first);
	glutKeyboardFunc(keyboard2);
	
	housewall = glutCreateMenu(housewallfunc);
	glutAddMenuEntry("Use LineLoop ", 1);
	glutAddMenuEntry("Use Polygon ", 2);

	lightsonoff = glutCreateMenu(lightsfunc);
	glutAddMenuEntry("On ", 1);
	glutAddMenuEntry("Off ", 2);

	viewtype = glutCreateMenu(viewtypefunc);
	glutAddMenuEntry("Orthographic View ", 1);
	glutAddMenuEntry("Perspective View ", 2);

	sofatranslate = glutCreateMenu(translatesofa);
	glutAddMenuEntry("On (Use keys w,a,s,d) ", 1);
	glutAddMenuEntry("Off ", 2);

	scalecompound = glutCreateMenu(scalecompoundheight);
	glutAddMenuEntry("x1 ", 1);
	glutAddMenuEntry("x1.5", 2);
	glutAddMenuEntry("x2.0", 3);
	glutAddMenuEntry("x2.5", 4);

	mouserotate = glutCreateMenu(rotateHouse);
	glutAddMenuEntry("Mouse On ", 1);
	glutAddMenuEntry("Mouse Off ", 2);

	rotatefan = glutCreateMenu(rotateMenu);
	glutAddMenuEntry("On ", 1);
	glutAddMenuEntry("Off ", 2);
	glutAddMenuEntry("Increase speed ", 3);
	glutAddMenuEntry("Decrease speed ", 4);

	c_smenu = glutCreateMenu(backMenu);
	glutAddMenuEntry("Red ", 1);
	glutAddMenuEntry("Blue ", 2);
	glutAddMenuEntry("Grean ", 3);
	glutAddMenuEntry("Black ", 4);

	glutCreateMenu(main_menu);
	glutAddMenuEntry("Exit", 1);
	glutAddSubMenu("Rotation of fan", rotatefan);
	glutAddSubMenu("Change Color", c_smenu);
	glutAddSubMenu("House Rotation", mouserotate);
	glutAddSubMenu("Translate Sofa", sofatranslate);
	glutAddSubMenu("Scale the height of compound wall", scalecompound);
	glutAddSubMenu("Lighting", lightsonoff);
	glutAddSubMenu("View", viewtype);
	glutAddSubMenu("House Walls", housewall);
	glutAddMenuEntry("Default Mode", 9);
	glutAttachMenu(GLUT_RIGHT_BUTTON);
	glutMainLoop();
	return 0;
}
Ejemplo n.º 2
0
void findcore(allinfo *a)
{
  register item *i, *m;
  register itype p, r;
  item *j, *s, *t, *b;

  /* all items apart from b must be in intervals */
  s = t = b = a->b;
  if (a->fpart <= b-1) push(a, LEFT,  a->fpart, b-1);
  if (b+1 <= a->lpart) push(a, RIGHT, b+1, a->lpart);

  /* initial core is b-1, b, b+1 (if these exist) */
  if (b-1 >= a->fitem) { swapout(a, b-1, LEFT); s--; }
  if (b+1 <= a->litem) { swapout(a, b+1, RIGHT); t++; }

  /* forward greedy solution */
  if (b-1 >= a->fitem) {
    p = 0; r = a->c - a->wsumb + (b-1)->w;
    for (i = t+1, m = a->litem+1, j = NULL; i != m; i++) {
      if ((i->w <= r) && (i->p > p)) { p = i->p; j = i; }
    }
    if (j != NULL) { swapout(a, j, RIGHT); t++; }
  }

  /* second forward greedy solution */
  if (TRUE) {
    p = 0; r = a->c - a->wsumb;
    for (i = t+1, m = a->litem+1, j = NULL; i != m; i++) {
      if ((i->w <= r) && (i->p > p)) { p = i->p; j = i; }
    }
    if (j != NULL) { swapout(a, j, RIGHT); t++; }
  }

  /* backward greedy solution */
  if (TRUE) {
    j = NULL; r = a->wsumb - a->c + b->w;
    for (i = a->fitem, m = s; i != m; i++) if (i->w >= r) { p = i->p+1; break; }
    for (; i != m; i++) if ((i->w >= r) && (i->p < p)) { p = i->p; j = i; }
    if (j != NULL) { swapout(a, j, LEFT); s--; }
  }

  /* second backward solution */
  if (b+1 <= a->litem) {
    j = NULL; r = a->wsumb - a->c + b->w + (b+1)->w;
    for (i = a->fitem, m = s; i != m; i++) if (i->w >= r) { p = i->p+1; break; }
    for (; i != m; i++) if ((i->w >= r) && (i->p < p)) { p = i->p; j = i; }
    if (j != NULL) { swapout(a, j, LEFT); s--; }
  }

  /* add first and last item to ensure some variation in weights */
  if (a->fitem < s) { s--; swapout(a, a->fitem, LEFT); }
  if (a->litem > t) { t++; swapout(a, a->litem, RIGHT); }


  /* enumerate core: reductions are not allowed! */
  initfirst(a, a->psumb, a->wsumb); moveset(a);
  for (i = b, j = b-1; (i <= t) || (j >= s); ) {
    if (i <= t) { multiply(a, i,  RIGHT); moveset(a); i++; }
    if (j >= s) { multiply(a, j,  LEFT);  moveset(a); j--; }
  }
  a->s = s-1; a->fsort = s;
  a->t = t+1; a->lsort = t;
}
Ejemplo n.º 3
0
stype minknap(int n, int *p, int *w, int *x, int c)
{
  allinfo a;
  item* tab;//[KNAPSIZE];
  static item tabmem[KNAPSIZE];
  interval* inttab;//[KNAPSIZE];
  static interval inttabmem[SORTSTACK];

  /* allocate space for internal representation */
  //tab = (item *) palloc(sizeof(item) * n);
  tab = tabmem;//(item *) palloc(sizeof(item) * n);
  a.fitem = &tab[0]; a.litem = &tab[n-1];
  copyproblem(a.fitem, a.litem, p, w, x);
  a.n           = n;
  a.cstar       = c;

  a.iterates    = 0;
  a.simpreduced = 0;
  a.pireduced   = 0;
  a.pitested    = 0;
  a.maxstates   = 0;
  a.coresize    = 0;

  //inttab  = (interval*) palloc(sizeof(interval) * SORTSTACK);
  inttab  = inttabmem;
  a.intv1 = a.intv1b = &inttab[0];
  a.intv2 = a.intv2b = &inttab[SORTSTACK - 1];
  a.fsort = a.litem; a.lsort = a.fitem;
  partsort(&a, a.fitem, a.litem, 0, PARTIATE);
  findbreak(&a);

  a.ub        = a.dantzig;
  a.firsttime = TRUE;

  for (;;) {
    a.iterates++;

    a.s = a.b-1;
    a.t = a.b;
    initfirst(&a, a.psumb, a.wsumb);
    initvect(&a);
    reduceset(&a);

    while ((a.d.size > 0) && (a.z < a.ub)) {
      if (a.t <= a.lsort) {
	if (haschance(&a, a.t, RIGHT)) multiply(&a, a.t, RIGHT);
	(a.t)++;
      }
      reduceset(&a);
      if (a.s >= a.fsort) {
	if (haschance(&a, a.s, LEFT)) multiply(&a, a.s, LEFT);
	(a.s)--;
      }
      reduceset(&a);
    }
    //pfree(a.d.set1);

    definesolution(&a);
    if (a.welldef) break;
  }
  //pfree(tab);
  //pfree(inttab);
  return a.zstar;
}