Example #1
0
//structured monte carlo
//maintains correct blockstructure doesnt work very good
void oku_mcblksol(oku_sod* sod, double temp){
	int i,j,k,val;
	int fit1, fit2, num,blk,idx1,idx2,tmp;
	int size = sod->size;
	int blkunk[size],cnt[size];
	int blkunkidx[size][size];

	for(i=0;i<size;i++){
		blkunk[i] = 0;
		for(j=0;j<size;j++)
			cnt[j] = 0;

		//find unknowns for every block
		for(j=0;j<size;j++){
			val = get_blk(sod,i,j);
			if(val == 0){
				blkunkidx[i][blkunk[i]++] = j;
			} else {
				if(cnt[val-1] == 0){
					cnt[val-1] = 1;
				} else printf("Fehler in oku_mcblocksol: Invalid hint: %d\n",val);
			}
		}

		//fill them
		k=0;
		for(j=0;j<size;j++)
			if(cnt[j] == 0)
				set_blk(sod,i,blkunkidx[i][k++],j+1);
	}

	oku_sod_print(sod);

	fit1 = fitness(sod);
	num = 0;
	while(fit1){
		//choose block and two indizes inside
		blk = rndi() % size;
		idx1 = rndi() % blkunk[blk];
		idx2 = rndi() % blkunk[blk];

		//swap
		tmp = get_blk(sod,blk,idx1);
		set_blk(sod,blk,idx1,get_blk(sod,blk,idx2));
		set_blk(sod,blk,idx2,tmp);

		fit2 = fitness(sod); 

		if(fit2 > fit1 && exp((fit1 - fit2)/temp) < rndf()){
			//swap back
			tmp = get_blk(sod,blk,idx1);
			set_blk(sod,blk,idx1,get_blk(sod,blk,idx2));
			set_blk(sod,blk,idx2,tmp);
		} else fit1 = fit2;
		num++;
		if(num % 2000 == 0)
			printf("Step:%d Fitness: %d\n",num,fit1);
	}

}
Example #2
0
int
video_move_cursor(int n, int del) {
	int new_pos = blk_pos + n;

	if (del) {
		int i;
		if (n < 0) {
			for (i = 0; i < -n; i++) {
				uint16_t del_pos = blk_pos + i;
				uint16_t rep_pos = new_pos + i;
				int rep_char = (del_pos <= crt_pos) ? crt_buf[del_pos] : 'X';
				rep_char = ':';
				crt_buf[rep_pos] = rep_char;
				//video_putc(rep_char);
			}
			blk_pos = new_pos;
		}
	} else {
		blk_pos = new_pos;
	}

	set_blk(blk_pos);

	return 1;
}
Example #3
0
int main(void)
{
    int ntowrite, nwrite;
    char *ptr;
    
    ntowrite = read(STDIN_FILENO, buf, sizeof(buf));
    fprintf(stderr, "read %d bytes\n",ntowrite);

    set_blk(STDOUT_FILENO, O_NONBLOCK);

    for(ptr = buf; ntowrite > 0; )
    {
        errno = 0;
        nwrite = write(STDOUT_FILENO, ptr, ntowrite);
        fprintf(stderr, "nwrite = %d, errno = %d\n", nwrite, errno);
        if(nwrite > 0)
        {
            ptr += nwrite;
            ntowrite -= nwrite;
        }
    }

    clr_blk(STDOUT_FILENO, O_NONBLOCK);
    exit(0);

}
Example #4
0
void
video_putc(int c)
{
	int i,temp,temp2;
	// if no attribute given, then use black on white
	if (!(c & ~0xFF))
		c |= 0x0700;
	switch (c & 0xff) {
	case '\b':
		if (blk_pos > line_pos){
			crt_buf[blk_pos-1] = (c & ~0xff) | ' ';
			for (i=blk_pos-1;i<crt_pos;++i){
				crt_buf[i] = crt_buf[i+1];
			}
			blk_pos--;
			crt_pos--;
		}
		break;
	case '\n':
		crt_pos += CRT_COLS;
		blk_pos = crt_pos;
		line_pos = crt_pos + 2;
		/* fallthru */
	case '\r':
		// blk_right();
		crt_pos -= (crt_pos % CRT_COLS);
		blk_pos = crt_pos;
		line_pos = crt_pos + 2;
		break;
	case '\t':
		video_putc(' ');
		video_putc(' ');
		video_putc(' ');
		video_putc(' ');
		video_putc(' ');
		blk_pos = crt_pos;
		break;
	default:
		// basically just shifts all the characters in the buffer that are to the right of the blinker position to the right
		temp = crt_buf[blk_pos];
		crt_buf[blk_pos] = c;
		for (i=blk_pos+1;i<crt_pos+1;i++){
			temp2 = crt_buf[i];
			crt_buf[i] = temp;
			temp = temp2;
		}
		crt_pos++;
		blk_pos++;
		break;
	}
	// the following just resizes the window
	if (crt_pos >= CRT_SIZE) {
		int i;
		memmove(crt_buf, crt_buf + CRT_COLS,
			(CRT_SIZE - CRT_COLS) * sizeof(uint16_t));
		for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++)
			crt_buf[i] = 0x0700 | ' ';
		crt_pos -= CRT_COLS;
		blk_pos = crt_pos;
		line_pos = crt_pos + 2;
	}
	/* move that little blinky thing */
	set_blk(blk_pos);
}
Example #5
0
void
to_end(){
	blk_pos = crt_pos;
	set_blk(blk_pos);
}
Example #6
0
void
to_begin(){
	blk_pos = line_pos;
	set_blk(blk_pos);
}
Example #7
0
void blk_right(){
	if (blk_pos < crt_pos){
		blk_pos++;
		set_blk(blk_pos);
	}
}
Example #8
0
void blk_left(){
	if (blk_pos > line_pos){
		blk_pos--;
		set_blk(blk_pos);
	}
}