Example #1
0
File: FED.C Project: MegaGod/TW
void pan_left( void ) {
	del_col( 0 );
}
Example #2
0
File: FED.C Project: MegaGod/TW
void edit( int ch ) {
	struct viewporttype tmp;
	char key, *buff;

	take_char( ( char ) ch );
	backup_char( );
	getviewsettings( &tmp );
	setviewport( 400, 30, getmaxx( ), getmaxy( ), 1 );
	buff = ( char* ) malloc( imagesize( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ) ) );
	getimage( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ), buff );
	draw_char( );
	start_clock( EDIT_FONT );

	while ( ( key = get_pos( &pos_x, &pos_y, X - 1, Y - 1, 1, 1 ) ) != 3 ) {
		switch ( tolower( key ) ) {
		case 1:
			xor_dot( pos_x, pos_y );
			continue;

		case '8':
			pan_up( );
			draw_char( );
			break;

		case '2':
			pan_down( );
			draw_char( );
			break;

		case '4':
			pan_left( );
			draw_char( );
			break;

		case '6':
			pan_right( );
			draw_char( );
			break;

		case 'r':
			insert_row( pos_y );
			draw_char( );
			break;

		case 'c':
			insert_col( pos_x );
			draw_char( );
			break;

		case 'e':
			del_row( pos_y );
			draw_char( );
			break;

		case 'd':
			del_col( pos_x );
			draw_char( );
			break;

		case 'i':
			invert( );
			draw_char( );
			break;

		case 'm':
			mirror( );
			draw_char( );
			break;

		case '.':
			++draw_mode;
			switch ( draw_mode ) {
			case 0:
				break;
			case 1:
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
				break;
			case 2:
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
				break;
			case 3:
				draw_mode = 0;
			}
			continue;

		case 'u':
			undo( );
			draw_char( );
			goto exit;

		case '?':
			help( );
			break;

		default:
			if ( draw_mode == 1 ) {
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
			}
			if ( draw_mode == 2 ) {
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
			}

		}
	}
	update_char( ( char ) ch );
exit:
	putimage( 0 + align, 0, buff, COPY_PUT );
	free( buff );
	stop_clock( );
	dispblank( 50, 16, strlen( "Move mode" ), 0 );
	setviewport( tmp.left, tmp.top, tmp.right, tmp.bottom, tmp.clip );
	print_table( which_page( ch ) );
}
Example #3
0
static VARIABLE *variable_branching(int type)

{
    int      k,card;
    double   val,val0,val1,lb0,lb1,minim;
    VARIABLE *col;
    VARIABLE **stack;
    int      sort_var(const void*,const void*);

    col = NULL;

    card = 0;
    for(k=0;k<nsupport;k++)
        if( fabs( support[k]->val - 0.5 ) < FRAC-ZERO ) card++;
    if( card==0 ){        
        std::cout << "ERROR: no fractional variables (FRAC=" << FRAC << std::endl;
        write_sol(fsolution);
        CSPexit(EXIT_ERROR); //exit(1);
    }

    switch(type){
    case NEAR05:
        minim = FRAC;
        for(k=0;k<nsupport;k++){
            val = fabs( support[k]->val - 0.5 );
            if( val < minim ){
                minim = val;
                col   = support[k];
            }
        }
        return( col );
    case BETTERLP:
        stack = (VARIABLE **)malloc( card * sizeof( VARIABLE * ) );
        if( stack==NULL ){            
            std::cout << "ERROR: not memory for 'frac' in branching" << std::endl;
            CSPexit(EXIT_ERROR); //exit(1);
        }
        card = 0;
        for(k=0;k<nsupport;k++)
            if( fabs( support[k]->val - 0.5 ) < FRAC-ZERO )
                stack[card++] = support[k];
        qsort( (char *)stack , card , sizeof(VARIABLE *) , sort_var );

        if(card > NUMB) card = NUMB;

        minim = lowerb - 1;
        for(k=0;k<card;k++){
            activa_pricing();
            val0 = solve_child_col( stack[k] , (double)0 , 0);
            lb0  = ceil( val0 -ZERO ) + ZERO;
            activa_pricing();
            val1 = solve_child_col( stack[k] , (double)1 , 0);
            lb1  = ceil( val1 -ZERO ) + ZERO;
            if( lb0 > upperb && lb1 > upperb ) {
                lowerb = upperb;
                free( stack );
                stack = NULL; /*PWOF*/
                return(NULL);
            }
            if( lb0 > upperb ) {
                del_col( stack[k] , FIX_UB );
                free( stack );
                stack = NULL; /*PWOF*/
                return(NULL);
            }
            if( lb1 > upperb ) {
                del_col( stack[k] , FIX_LB );
                free( stack );
                stack = NULL; /*PWOF*/
                return(NULL);
            }
            val  = PROP * val0 + (1-PROP) * val1;
            if( val > minim ){
                minim = val;
                col   = stack[k];
            }
        }
        free( stack );
        stack = NULL; /*PWOF*/
        return( col );
    default:        
        std::cout << "ERROR: unknown type of branching" << std::endl;
        CSPexit(EXIT_ERROR); //exit(1);
    }
    return( NULL );
}