int main(int argc, char *argv[]) {
    Funenv functions = mkFunenv(NULL, NULL);
    Valenv globals   = mkValenv(NULL, NULL);
    int doprompt = (argc <= 1) || (strcmp(argv[1], "-q") != 0);
    Prompts prompts = doprompt ? STD_PROMPTS : NO_PROMPTS;
    XDefreader input = xdefreader(filereader("standard input", stdin), prompts);
    /* install conversion specifications in print module 50c */
    installprinter('d', printdecimal);
    installprinter('e', printexp);
    installprinter('E', printexplist);
    installprinter('f', printfun);
    installprinter('n', printname);
    installprinter('N', printnamelist);
    installprinter('p', printpar);
    installprinter('P', printparlist);
    installprinter('s', printstring);
    installprinter('t', printdef);
    installprinter('v', printvalue);
    installprinter('V', printvaluelist);
    /* install the initial basis in [[functions]] 51a */
    {
        static char *prims[] = { "+", "-", "*", "/", "<", ">", "=", "print", 0 }
                                                                               ;
        char **p;
        for (p=prims; *p; p++) {
            Name n = strtoname(*p);
            bindfun(n, mkPrimitive(n), functions);
        }
    }
    /* install the initial basis in [[functions]] 51c */
    {

  /* C representation of initial basis for {\impcore} (generated by a script) */
      /*Adding empty local evironment to the functions in the initial basis => "()" */
        const char *basis=
          "(define and (b c) () (if b c b))\n"
          "(define or  (b c) () (if b b c))\n"
          "(define not (b)   () (if b 0 1))\n"
          "(define <= (x y) () (not (> x y)))\n"
          "(define >= (x y) () (not (< x y)))\n"
          "(define != (x y) () (not (= x y)))\n"
          "(define mod (m n) () (- m (* n (/ m n))))\n";
        if (setjmp(errorjmp))
            assert(0); /* fail if error in basis */
        readevalprint(xdefreader(stringreader("initial basis", basis),
                                                                    NO_PROMPTS),
                      globals, functions, SILENT);
    }
    while (setjmp(errorjmp))
        ;
    readevalprint(input, globals, functions, ECHOING);
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char* argv[]) {
    filereader(objectfile[0]);
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
    glutInitWindowSize(WindowParams::WindowWidth,WindowParams::WindowHeight);
    WindowParams::MainWindow = glutCreateWindow("Homework 3: Meshes and subdivision");
    glutDisplayFunc(Draw); 
    glutReshapeFunc(Reshape);
    glutMouseFunc(MouseClick);
    glutMotionFunc(MouseMotion);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
    return 0;
}
/*
 * Function [[readevalprint]] evaluates definitions,
 * updates the environment [[*envp]], and remembers unit
 * tests. [*]
 * <evaldef.c>=
 */
void readevalprint(XDefreader reader, Env *envp, Echo echo) {
    XDef d;
    UnitTestlist unit_tests = NULL;

    while ((d = readxdef(reader)))
    switch (d->alt) {
    case DEF:
        *envp = evaldef(d->u.def, *envp, echo);
        break;
    case USE:
        /*
         * Reading a file is as in Impcore, except that
         * in micro-Scheme, we cannot mutate an environment.
         * We therefore pass [[readevalprint]] a pointer to the
         * environment [[env]], and when [[readevalprint]]
         * evaluates a definition, it writes a new environment
         * in place of the old one.
         * <read in a file and update [[*envp]]>=
         */
        {
            const char *filename = nametostr(d->u.use);
            FILE *fin = fopen(filename, "r");
            if (fin == NULL)
                error("cannot open file \"%s\"", filename);
            readevalprint(xdefreader(filereader(filename, fin), NO_PROMPTS),
                                                                 envp, ECHOING);
            fclose(fin);
        }
        break;
    case TEST:
        unit_tests = mkUL(d->u.test, unit_tests);
        break;
    default:
        assert(0);
    }

    set_error_mode(TESTING);
    /*
     * <run the remembered [[unit_tests]], last one first>=
     */
    {   int npassed = tests_passed(unit_tests, *envp);
        int ntests  = lengthUL(unit_tests);
        report_test_results(npassed, ntests);
    }
    set_error_mode(NORMAL);
}
Exemplo n.º 4
0
void keyboard(unsigned char c, int x, int y){
    switch(c){
    case '1':
	filereader(objectfile[0]);
	glutPostRedisplay();
	break;
    case '2':
	filereader(objectfile[1]);
	glutPostRedisplay();
	break;
    case '3':  
	filereader(objectfile[2]);
	glutPostRedisplay();
	break;
    case '4':
	filereader(objectfile[3]);
	glutPostRedisplay();
	break;
    case '5':
	filereader(objectfile[4]);
	glutPostRedisplay();
	break;
    case '6':   
	filereader(objectfile[5]);
	glutPostRedisplay();
	break;
    case 't':
    case 'T':
	triangularizationte();
        glutPostRedisplay();
    break;
    case 'd':
    case 'D':
	facedeleter();
        glutPostRedisplay();
    break;
    case 's':
    case 'S':
	triangularizationte();
        loop_scheme();
        glutPostRedisplay();
    break;
    case 27:
	exit(0);
	break;
    default:
	break;
    }
}
Exemplo n.º 5
0
int main(int argc, char** argv){
	FILE* in = stdin;
	int bflag = 0;
	int n = 1000;
	char* sym = (char *) malloc(sizeof(char*));
	int i;
	for(i = 1; i < argc; i++){
		if(!strcmp(argv[i], "-i"))
			in = fopen(argv[++i], "r");
		if(!strcmp(argv[i], "-b"))
			bflag = 1;
		if(!strcmp(argv[i], "-s"))
			strcpy(sym, argv[++i]);
		if(!strcmp(argv[i], "-n"))
			n = atoi(argv[++i]);
		//	printf("n in for %d\n", n);
	}
			//	printf("n %d\n", n);
//	hashInit();
	filereader(in, bflag, sym, n);
}
Exemplo n.º 6
0
void load_truecolor_tiles(Fl_Widget*,void*){
	if(!currentProject->containsData(pjHaveTiles)){
		currentProject->haveMessage(pjHaveTiles);
		return;
	}
	//start by loading the file
	filereader f=filereader("Load truecolor tiles");
	if(!f.amt)
		return;
	unsigned i=f.selDat();
	size_t file_size = f.lens[i];
	if (file_size&255){
		fl_alert("Error: this file is not a multiple of 256 so it is not a valid truecolor tiles. The file size is: %d",file_size);
		return;
	}
	currentProject->tileC->truetDat.resize(file_size);
	currentProject->tileC->tDat.resize(file_size*currentProject->tileC->tileSize/currentProject->tileC->tcSize);
	memcpy(currentProject->tileC->truetDat.data(),f.dat[i],file_size);
	currentProject->tileC->amt=file_size/256;
	updateTileSelectAmt();
	window->redraw();
}
/* evaldef.c 149b */
void readevalprint(XDefreader reader, Env *envp, Echo echo) {
    XDef d;
    UnitTestlist unit_tests = NULL;

    while ((d = readxdef(reader)))
    switch (d->alt) {
    case DEF:
        *envp = evaldef(d->u.def, *envp, echo);
        break;
    case USE:
        /* read in a file and update [[*envp]] 149a */
        {
            const char *filename = nametostr(d->u.use);
            FILE *fin = fopen(filename, "r");
            if (fin == NULL)
                error("cannot open file \"%s\"", filename);
            readevalprint(xdefreader(filereader(filename, fin), NO_PROMPTS),
                                                                 envp, ECHOING);
            fclose(fin);
        }
        break;
    case TEST:
        unit_tests = mkUL(d->u.test, unit_tests);
        break;
    default:
        assert(0);
    }

    set_error_mode(TESTING);
    /* run the remembered [[unit_tests]], last one first 712d */
    {   int npassed = tests_passed(unit_tests, *envp);
        int ntests  = lengthUL(unit_tests);
        report_test_results(npassed, ntests);
    }
    set_error_mode(NORMAL);
}
int main(int argc, char *argv[]) {
    Env env;
    XDefreader input;
    int doprompt = (argc <= 1) || (strcmp(argv[1], "-q") != 0);
    Prompts prompts = doprompt ? STD_PROMPTS : NO_PROMPTS;

    initvalue();
    initallocate();
    /*
     * We have many printers.
     * <install printers>=
     */
    installprinter('c', printclosure);
    installprinter('d', printdecimal);
    installprinter('e', printexp);
    installprinter('E', printexplist);
    installprinter('\\', printlambda);
    installprinter('n', printname);
    installprinter('N', printnamelist);
    installprinter('p', printpar);
    installprinter('P', printparlist);
    installprinter('r', printenv);
    installprinter('s', printstring);
    installprinter('t', printdef);
    installprinter('v', printvalue);
    installprinter('V', printvaluelist);
    installprinter('%', printpercent);
    env = primenv();
    /*
     * As in the Impcore interpreter, the C representation
     * of the initial basis is generated automatically from
     * code in [[<<additions to the micro-Scheme initial
     * basis>>]].
     * <install into [[env]] the additions to the initial basis>=
     */
    {
        /*
         * <C representation of initial basis for {\uscheme}>=
         */
        const char *basis=
          "(define caar (xs) (car (car xs)))\n"
          "(define cadr (xs) (car (cdr xs)))\n"
          "(define cdar (xs) (cdr (car xs)))\n"
          "(define list1 (x)     (cons x '()))\n"
          "(define list2 (x y)   (cons x (list1 y)))\n"
          "(define list3 (x y z) (cons x (list2 y z)))\n"
          "(define length (xs)\n"
          "  (if (null? xs) 0\n"
          "    (+ 1 (length (cdr xs)))))\n"
          "(define and (b c) (if b  c  b))\n"
          "(define or  (b c) (if b  b  c))\n"
          "(define not (b)   (if b #f #t))\n"

"(define atom? (x) (or (number? x) (or (symbol? x) (or (boolean? x) (null? x)))))\n"
          "(define equal? (s1 s2)\n"
          "  (if (or (atom? s1) (atom? s2))\n"
          "    (= s1 s2)\n"
          "    (and (equal? (car s1) (car s2)) (equal? (cdr s1) (cdr s2)))))\n"
          "(define append (xs ys)\n"
          "  (if (null? xs)\n"
          "     ys\n"
          "     (cons (car xs) (append (cdr xs) ys))))\n"
          "(define revapp (xs ys)\n"
          "  (if (null? xs)\n"
          "     ys\n"
          "     (revapp (cdr xs) (cons (car xs) ys))))\n"
          "(define reverse (xs) (revapp xs '()))\n"
          "(define mk-alist-pair (k a) (list2 k a))\n"
          "(define alist-pair-key        (pair)  (car  pair))\n"
          "(define alist-pair-attribute  (pair)  (cadr pair))\n"

   "(define alist-first-key       (alist) (alist-pair-key       (car alist)))\n"

   "(define alist-first-attribute (alist) (alist-pair-attribute (car alist)))\n"
          "(define bind (k a alist)\n"
          "  (if (null? alist)\n"
          "    (list1 (mk-alist-pair k a))\n"
          "    (if (equal? k (alist-first-key alist))\n"
          "      (cons (mk-alist-pair k a) (cdr alist))\n"
          "      (cons (car alist) (bind k a (cdr alist))))))\n"
          "(define find (k alist)\n"
          "  (if (null? alist) '()\n"
          "    (if (equal? k (alist-first-key alist))\n"
          "      (alist-first-attribute alist)\n"
          "      (find k (cdr alist)))))\n"
          "(define o (f g) (lambda (x) (f (g x))))\n"
          "(define curry   (f) (lambda (x) (lambda (y) (f x y))))\n"
          "(define uncurry (f) (lambda (x y) ((f x) y)))\n"
          "(define filter (p? xs)\n"
          "  (if (null? xs)\n"
          "    '()\n"
          "    (if (p? (car xs))\n"
          "      (cons (car xs) (filter p? (cdr xs)))\n"
          "      (filter p? (cdr xs)))))\n"
          "(define map (f xs)\n"
          "  (if (null? xs)\n"
          "    '()\n"
          "    (cons (f (car xs)) (map f (cdr xs)))))\n"
          "(define exists? (p? xs)\n"
          "  (if (null? xs)\n"
          "    #f\n"
          "    (if (p? (car xs)) \n"
          "      #t\n"
          "      (exists? p? (cdr xs)))))\n"
          "(define all? (p? xs)\n"
          "  (if (null? xs)\n"
          "    #t\n"
          "    (if (p? (car xs))\n"
          "      (all? p? (cdr xs))\n"
          "      #f)))\n"
          "(define foldr (op zero xs)\n"
          "  (if (null? xs)\n"
          "    zero\n"
          "    (op (car xs) (foldr op zero (cdr xs)))))\n"
          "(define foldl (op zero xs)\n"
          "  (if (null? xs)\n"
          "    zero\n"
          "    (foldl op (op (car xs) zero) (cdr xs))))\n"
          "(define <= (x y) (not (> x y)))\n"
          "(define >= (x y) (not (< x y)))\n"
          "(define != (x y) (not (= x y)))\n"
          "(define max (x y) (if (> x y) x y))\n"
          "(define min (x y) (if (< x y) x y))\n"
          "(define mod (m n) (- m (* n (/ m n))))\n"
          "(define gcd (m n) (if (= n 0) m (gcd n (mod m n))))\n"
          "(define lcm (m n) (if (= m 0) 0 (* m (/ n (gcd m n)))))\n"
          "(define caar  (sx) (car (car  sx)))\n"
          "(define cdar  (sx) (cdr (car  sx)))\n"
          "(define cadr  (sx) (car (cdr  sx)))\n"
          "(define cddr  (sx) (cdr (cdr  sx)))\n"
          "(define caaar (sx) (car (caar sx)))\n"
          "(define cdaar (sx) (cdr (caar sx)))\n"
          "(define caadr (sx) (car (cadr sx)))\n"
          "(define cdadr (sx) (cdr (cadr sx)))\n"
          "(define cadar (sx) (car (cdar sx)))\n"
          "(define cddar (sx) (cdr (cdar sx)))\n"
          "(define caddr (sx) (car (cddr sx)))\n"
          "(define cdddr (sx) (cdr (cddr sx)))\n"
          "(define list1 (x)               (cons x '()))\n"
          "(define list2 (x y)             (cons x (list1 y)))\n"
          "(define list3 (x y z)           (cons x (list2 y z)))\n"
          "(define list4 (x y z a)         (cons x (list3 y z a)))\n"
          "(define list5 (x y z a b)       (cons x (list4 y z a b)))\n"
          "(define list6 (x y z a b c)     (cons x (list5 y z a b c)))\n"
          "(define list7 (x y z a b c d)   (cons x (list6 y z a b c d)))\n"
          "(define list8 (x y z a b c d e) (cons x (list7 y z a b c d e)))\n";

        if (setjmp(errorjmp))
            assert(0);  /* fail if error occurs in basis */
        readevalprint(xdefreader(stringreader("initial basis", basis),
                                                     NO_PROMPTS), &env, SILENT);
    }

    input = xdefreader(filereader("standard input", stdin), prompts);

    while (setjmp(errorjmp))
        ;
    readevalprint(input, &env, ECHOING);
    return 0;
}
Exemplo n.º 9
0
void load_tiles(Fl_Widget*,void*o){
	//if o=0 load if o=1 append if o=2 load at
	if(!currentProject->containsData(pjHaveTiles)){
		currentProject->haveMessage(pjHaveTiles);
		return;
	}
	size_t file_size;
	unsigned mode=(uintptr_t)o;
	char * returned=(char*)fl_input("What row should these tiles use?\nEnter 0 to 3 to selected a row or -1 to -4 to auto determine based on tilemap\nWhen specifing a negative number to figure out what the default will be use this formula abs(row)-1","-1");
	if (unlikely(!returned))
		return;
	if (unlikely(!verify_str_number_only(returned)))
		return;
	int row=atoi(returned);
	if (unlikely((row > 3) || (row < -4))){
		fl_alert("You entered %d which is out of range it must be in range of -4 to 3",row);
		return;
	}
	uint8_t defaultRow=row >= 0 ? row:abs(row)-1;
	int compression=compressionAsk();
	bool alphaZero=fl_ask("Set color #0 to alpha 0 instead of 255")?true:false;
	void*output;
	filereader f=filereader("Load tiles");
	if(f.amt==0)
		return;
	unsigned idx=f.selDat();
	file_size = f.lens[idx];
	unsigned truecolor_multiplier;
	truecolor_multiplier=256/currentProject->tileC->tileSize;
	if(compression)
		output=decodeTypeRam((uint8_t*)f.dat[idx],f.lens[idx],file_size,compression);
	else{
		if (file_size%currentProject->tileC->tileSize){
			fl_alert("Error: This is not a valid tile file each tile is %d bytes and this file is not a multiple of %d so it is not a valid tile file",currentProject->tileC->tileSize,currentProject->tileC->tileSize);
			return;
		}
	}
	uint32_t offset_tiles;
	uint32_t offset_tiles_bytes;
	if(mode==2){
		const char * str=fl_input("Counting from zero which tile should this start at?");
		if(!str){
			return;
		}
		if(!verify_str_number_only((char*)str)){
			return;
		}
		int off=atoi(str);
		if(off>=0){
			offset_tiles=off;
			offset_tiles_bytes=offset_tiles*currentProject->tileC->tileSize;
		}else{
			fl_alert("You must enter a number greater than or equal to zero");
			return;
		}
	}else if(mode==1){
		offset_tiles=currentProject->tileC->amt;
		offset_tiles_bytes=offset_tiles*currentProject->tileC->tileSize;
	}else{
		offset_tiles=0;
		offset_tiles_bytes=0;
	}
	if(mode==2){
		if(offset_tiles+(file_size/currentProject->tileC->tileSize)>=currentProject->tileC->amt)
			currentProject->tileC->tDat.resize(offset_tiles_bytes+file_size);
	}else
		currentProject->tileC->tDat.resize(offset_tiles_bytes+file_size);
	if(compression){
		memcpy(currentProject->tileC->tDat.data()+offset_tiles_bytes,output,file_size);
		free(output);
	}else
		memcpy(currentProject->tileC->tDat.data()+offset_tiles_bytes,f.dat[idx],file_size);
	if(currentProject->getTileType()!=PLANAR_TILE)
		currentProject->tileC->toPlanar(currentProject->getTileType(),offset_tiles,offset_tiles+(file_size/currentProject->tileC->tileSize));
	if(mode==2){
		if(offset_tiles+(file_size/currentProject->tileC->tileSize)>=currentProject->tileC->amt)
			currentProject->tileC->truetDat.resize((file_size*truecolor_multiplier)+(offset_tiles_bytes*truecolor_multiplier));
	}else
		currentProject->tileC->truetDat.resize((file_size*truecolor_multiplier)+(offset_tiles_bytes*truecolor_multiplier));
	for(uint32_t c=offset_tiles;c<(file_size/currentProject->tileC->tileSize)+offset_tiles;c++) {
		if(row < 0){
			uint32_t x,y;
			uint8_t foundRow=defaultRow;
			for(y=0;y<currentProject->tms->maps[currentProject->curPlane].mapSizeHA;++y){
				for(x=0;x<currentProject->tms->maps[currentProject->curPlane].mapSizeW;++x){
					if(currentProject->tms->maps[currentProject->curPlane].get_tile(x,y) == c) {
						foundRow=currentProject->tms->maps[currentProject->curPlane].getPalRow(x,y);
						goto doTile;
					}
				}
			}
doTile:
			currentProject->tileC->tileToTrueCol(&currentProject->tileC->tDat[(c*currentProject->tileC->tileSize)],&currentProject->tileC->truetDat[(c*256)],foundRow,true,alphaZero);
		}else
			currentProject->tileC->tileToTrueCol(&currentProject->tileC->tDat[(c*currentProject->tileC->tileSize)],&currentProject->tileC->truetDat[(c*256)],defaultRow,true,alphaZero);
	}
	if(mode==2){
		if(offset_tiles+(file_size/currentProject->tileC->tileSize)>=currentProject->tileC->amt){
			currentProject->tileC->amt=(file_size/currentProject->tileC->tileSize);
			currentProject->tileC->amt+=offset_tiles;
		}
	}else{
		currentProject->tileC->amt=(file_size/currentProject->tileC->tileSize);
		currentProject->tileC->amt+=offset_tiles;
	}
	updateTileSelectAmt();
	window->tile_select->value(0);
	window->tile_select_2->value(0);
	window->redraw();
}
Exemplo n.º 10
0
int main(int argc, char** argv)
{
	/*==================================================*/
	/* Variables */
	data d;
	int* M;

	/* GLPK */
	int *ia, *ja;
	double *ar;
	double z;
	double *x;
	int notZeroCount;

	/* Misc */
	int i, pos;

	/* Check up */
	if(argc != 2)
	{
		printf("ERROR : no data file !\n");
		exit(1);		
	}
	
	/* Initialization */
	filereader(argv[1], &d);

	if(d.nbjour < 1)
	{
		printf("Obvious...\n");
		return 0;	
	}
	
	M = (int*) malloc ((d.nbjour +1)* sizeof(int));
	M[d.nbjour] = d.d[d.nbjour];
	for (i = d.nbjour-1; i >=0; --i)
	{
		M[i] = d.d[i] + M[i+1];
	}

	/* Problem creation*/
	glp_prob *prob;
	prob = glp_create_prob();
	glp_set_prob_name(prob, "ULS");
	glp_set_obj_dir(prob, GLP_MIN);

	glp_smcp parm;
	glp_init_smcp(&parm);
	parm.msg_lev = GLP_MSG_OFF;

	glp_iocp parmip;
	glp_init_iocp(&parmip);
	parmip.msg_lev = GLP_MSG_OFF;

	/* Number of constraints : 2 * nbjour +2 */
	glp_add_rows(prob, 2*d.nbjour +2);
	for (i = 1; i <= d.nbjour; ++i)
	{
		glp_set_row_bnds(prob, i, GLP_FX, d.d[i], d.d[i]);
	}
	for (i = d.nbjour+1; i <= 2*d.nbjour; ++i)
	{
		glp_set_row_bnds(prob, i, GLP_LO, 0, 0);
	}	
	glp_set_row_bnds(prob, 2*d.nbjour+1, GLP_FX, 0.0, 0.0);
	glp_set_row_bnds(prob, 2*d.nbjour+2, GLP_FX, 0.0, 0.0);

	/* Number of variables : 3*(nbjour +1)*/
	glp_add_cols(prob, 3*(d.nbjour+1));
	for (i = 0; i < d.nbjour +1; ++i)
	{
		glp_set_col_bnds(prob, i*3 +1, GLP_LO, 0.0, 0.0);
		glp_set_col_bnds(prob, i*3 +2, GLP_LO, 0.0, 0.0);
		glp_set_col_bnds(prob, i*3 +3, GLP_DB, 0.0, 1.0);
	}
	for (i = 1; i <= 3*(d.nbjour+1); ++i)
	{
		glp_set_col_kind(prob, i, GLP_CV);
	}

	/* Coefficients of the economic function */
	glp_set_obj_coef(prob, 1, 0);
	glp_set_obj_coef(prob, 2, 0);
	glp_set_obj_coef(prob, 3, 0);
	for (i = 1; i <=d.nbjour; ++i)
	{
		glp_set_obj_coef(prob, 3*i+1, d.p[i]);
		glp_set_obj_coef(prob, 3*i+2, d.h[i]);
		glp_set_obj_coef(prob, 3*i+3, d.f[i]);
	}

	/* Matrix */
	notZeroCount = 5 * d.nbjour + 2;

	ia = (int *) malloc ((1+notZeroCount) * sizeof(int));
	ja = (int *) malloc ((1+notZeroCount) * sizeof(int));	
	ar = (double *) malloc ((1+notZeroCount) * sizeof(double));

	pos = 1;
	for (i = 1; i <= d.nbjour; ++i)
	{
		ia[pos] = i;
		ia[pos+1] = i;
		ia[pos+2] = i;

		ja[pos] = i*3-1;
		ja[pos+1] = i*3+1;
		ja[pos+2] = i*3+2;

		ar[pos] = 1.0;
		ar[pos+1] = 1.0;
		ar[pos+2] = -1.0;
			
		pos += 3;
	}

	for (i = 1; i <= d.nbjour; ++i)
	{
		ia[pos] = i + d.nbjour;
		ia[pos+1] = i + d.nbjour;

		ja[pos] = i*3+1;
		ja[pos+1] = i*3+3;

		ar[pos] = -1.0;
		ar[pos+1] = M[i];
			
		pos += 2;
	}
	
	ia[pos] = 2*d.nbjour +1;
	ia[pos+1] = 2 * d.nbjour+2;

	ja[pos] = 3*(d.nbjour+1)-1;
	ja[pos+1] = 2;

	ar[pos] = 1.0;
	ar[pos+1] = 1.0;

	pos += 2;

	glp_load_matrix(prob, notZeroCount, ia, ja , ar);

	/* Writing in a file */
	glp_write_lp(prob, NULL, "ULS.lp");

	/* Branch and bound */
	node* res = branchAndBound(prob);
	displayNode(res);
}
int main(int argc, char *argv[]) {
    Env env = NULL;
    int doprompt = (argc <= 1) || (strcmp(argv[1], "-q") != 0);

    initvalue();
    initallocate();
    /*
     * We have many printers.
     * <install printers>=
     */
    installprinter('c', printclosure);
    installprinter('d', printdecimal);
    installprinter('e', printexp);
    installprinter('E', printexplist);
    installprinter('\\', printlambda);
    installprinter('n', printname);
    installprinter('N', printnamelist);
    installprinter('p', printpar);
    installprinter('P', printparlist);
    installprinter('r', printenv);
    installprinter('s', printstring);
    installprinter('t', printdef);
    installprinter('v', printvalue);
    installprinter('V', printvaluelist);
    installprinter('%', printpercent);
    /*
     * <install printers>=
     */
    installprinter('S', printstack);
    installprinter('F', printoneframe);
    installprinter('R', printnoenv);
    roots.globals = &env;   
    roots.stack   = emptystack();
    addprimitives(&env);
    /*
     * Standard input should be read after the initial
     * basis, but because reading is done on a stack, we
     * push it on before the basis.
     * <initialize [[roots.sources]] to read first the initial basis, then
                                                                     [[stdin]]>=
     */
    roots.sources =
      mkSL(mkSource(xdefreader(filereader("standard input", stdin), doprompt), 
                    stdin, ECHOING),
           NULL);
    {   /*
         * <C representation of initial basis for {\uscheme}>=
         */
        const char *basis=
          "(define caar (xs) (car (car xs)))\n"
          "(define cadr (xs) (car (cdr xs)))\n"
          "(define cdar (xs) (cdr (car xs)))\n"
          "(define list1 (x)     (cons x '()))\n"
          "(define list2 (x y)   (cons x (list1 y)))\n"
          "(define list3 (x y z) (cons x (list2 y z)))\n"
          "(define length (xs)\n"
          "  (if (null? xs) 0\n"
          "    (+ 1 (length (cdr xs)))))\n"
          "(define and (b c) (if b  c  b))\n"
          "(define or  (b c) (if b  b  c))\n"
          "(define not (b)   (if b #f #t))\n"

"(define atom? (x) (or (number? x) (or (symbol? x) (or (boolean? x) (null? x)))))\n"
          "(define equal? (s1 s2)\n"
          "  (if (or (atom? s1) (atom? s2))\n"
          "    (= s1 s2)\n"
          "    (and (equal? (car s1) (car s2)) (equal? (cdr s1) (cdr s2)))))\n"
          "(define append (xs ys)\n"
          "  (if (null? xs)\n"
          "     ys\n"
          "     (cons (car xs) (append (cdr xs) ys))))\n"
          "(define revapp (xs ys)\n"
          "  (if (null? xs)\n"
          "     ys\n"
          "     (revapp (cdr xs) (cons (car xs) ys))))\n"
          "(define reverse (xs) (revapp xs '()))\n"
          "(define mk-alist-pair (k a) (list2 k a))\n"
          "(define alist-pair-key        (pair)  (car  pair))\n"
          "(define alist-pair-attribute  (pair)  (cadr pair))\n"

   "(define alist-first-key       (alist) (alist-pair-key       (car alist)))\n"

   "(define alist-first-attribute (alist) (alist-pair-attribute (car alist)))\n"
          "(define bind (k a alist)\n"
          "  (if (null? alist)\n"
          "    (list1 (mk-alist-pair k a))\n"
          "    (if (equal? k (alist-first-key alist))\n"
          "      (cons (mk-alist-pair k a) (cdr alist))\n"
          "      (cons (car alist) (bind k a (cdr alist))))))\n"
          "(define find (k alist)\n"
          "  (if (null? alist) '()\n"
          "    (if (equal? k (alist-first-key alist))\n"
          "      (alist-first-attribute alist)\n"
          "      (find k (cdr alist)))))\n"
          "(define o (f g) (lambda (x) (f (g x))))\n"
          "(define curry   (f) (lambda (x) (lambda (y) (f x y))))\n"
          "(define uncurry (f) (lambda (x y) ((f x) y)))\n"
          "(define filter (p? xs)\n"
          "  (if (null? xs)\n"
          "    '()\n"
          "    (if (p? (car xs))\n"
          "      (cons (car xs) (filter p? (cdr xs)))\n"
          "      (filter p? (cdr xs)))))\n"
          "(define map (f xs)\n"
          "  (if (null? xs)\n"
          "    '()\n"
          "    (cons (f (car xs)) (map f (cdr xs)))))\n"
          "(define exists? (p? xs)\n"
          "  (if (null? xs)\n"
          "    #f\n"
          "    (if (p? (car xs)) \n"
          "      #t\n"
          "      (exists? p? (cdr xs)))))\n"
          "(define all? (p? xs)\n"
          "  (if (null? xs)\n"
          "    #t\n"
          "    (if (p? (car xs))\n"
          "      (all? p? (cdr xs))\n"
          "      #f)))\n"
          "(define foldr (op zero xs)\n"
          "  (if (null? xs)\n"
          "    zero\n"
          "    (op (car xs) (foldr op zero (cdr xs)))))\n"
          "(define foldl (op zero xs)\n"
          "  (if (null? xs)\n"
          "    zero\n"
          "    (foldl op (op (car xs) zero) (cdr xs))))\n"
          "(define <= (x y) (not (> x y)))\n"
          "(define >= (x y) (not (< x y)))\n"
          "(define != (x y) (not (= x y)))\n"
          "(define max (x y) (if (> x y) x y))\n"
          "(define min (x y) (if (< x y) x y))\n"
          "(define mod (m n) (- m (* n (/ m n))))\n"
          "(define gcd (m n) (if (= n 0) m (gcd n (mod m n))))\n"
          "(define lcm (m n) (if (= m 0) 0 (* m (/ n (gcd m n)))))\n"
          "(define caar  (sx) (car (car  sx)))\n"
          "(define cdar  (sx) (cdr (car  sx)))\n"
          "(define cadr  (sx) (car (cdr  sx)))\n"
          "(define cddr  (sx) (cdr (cdr  sx)))\n"
          "(define caaar (sx) (car (caar sx)))\n"
          "(define cdaar (sx) (cdr (caar sx)))\n"
          "(define caadr (sx) (car (cadr sx)))\n"
          "(define cdadr (sx) (cdr (cadr sx)))\n"
          "(define cadar (sx) (car (cdar sx)))\n"
          "(define cddar (sx) (cdr (cdar sx)))\n"
          "(define caddr (sx) (car (cddr sx)))\n"
          "(define cdddr (sx) (cdr (cddr sx)))\n"
          "(define list1 (x)               (cons x '()))\n"
          "(define list2 (x y)             (cons x (list1 y)))\n"
          "(define list3 (x y z)           (cons x (list2 y z)))\n"
          "(define list4 (x y z a)         (cons x (list3 y z a)))\n"
          "(define list5 (x y z a b)       (cons x (list4 y z a b)))\n"
          "(define list6 (x y z a b c)     (cons x (list5 y z a b c)))\n"
          "(define list7 (x y z a b c d)   (cons x (list6 y z a b c d)))\n"
          "(define list8 (x y z a b c d e) (cons x (list7 y z a b c d e)))\n";
        roots.sources =
           mkSL(mkSource(xdefreader(stringreader("initial basis", basis), 0),
                                                                  NULL, SILENT),
                roots.sources);
    }

    /*
     * The loop looks a bit like the body of the old
     * [[readevalprint]]. This version is more resilient to
     * errors that occur when a file is read.
     * <read definitions until [[roots.sources]] is exhausted>=
     */
    while (roots.sources != NULL) {
        XDef d;
        Source *cursource = &roots.sources->hd;
        Source newsource;   /* initialized when we hit USE */

        while (setjmp(errorjmp))
            ;
        d = readxdef(cursource->xdefs);
        if (d == NULL) {
            if (cursource->sourcefile != NULL)
                fclose(cursource->sourcefile);
            /*
             * <using error mode [[TESTING]], run unit tests from
                                         [[cursource->tests]], last test first>=
             */
            set_error_mode(TESTING);
            {   int npassed = tests_passed(cursource->tests, *roots.globals);
                int ntests  = lengthUL(cursource->tests);
                report_test_results(npassed, ntests);
            }
            set_error_mode(NORMAL);
            roots.sources = popSL(roots.sources);
        } else switch (d->alt) {
            case USE:
                /*
                 * File [[fin]] is closed above, after [[readxdef
                 * (cursource->xdefs)]] returns [[NULL]].
                 * <set [[newsource]] to a definition reader for [[d->u.use]]>=
                 */
                {
                    const char *filename = nametostr(d->u.use);
                    FILE *fin = fopen(filename, "r");

                    if (fin == NULL)
                        error("cannot open file \"%s\"", filename);
                    newsource = mkSource(xdefreader(filereader(filename, fin), 0
                                                               ), fin, ECHOING);
                }
                roots.sources = mkSL(newsource, roots.sources);
                break;
            case TEST:
                cursource->tests = mkUL(d->u.test, cursource->tests);
                break;
            case DEF:
                env = evaldef(d->u.def, env, cursource->echo);
                break;
            default:
                assert(0);
        }
    }
    return 0;
}