Пример #1
0
int			main(int argc, char **argv)
{
  struct termios	oldline;
  t_area		ar;

  if (argc > 1)
    {
      non_canonical_mode(&oldline);
      init_term(&ar, argv, argc);
      display_arguments(&ar);
      while ((ar.len = read(0, ar.buff, sizeof(ar.buff))))
	{
	  x_read(ar.len);
	  init_lines(&ar, &oldline);
	  check_ctrl(&ar);
	  check_keys(&ar, ar.len);
	  check_select(&ar);
	  if (my_exit(&oldline, &ar) == 1 || void_exit(&ar, &oldline) == 1)
	    return (EXIT_SUCCESS);
	}
      restore_mode(&oldline, &ar);
      free_struct(&ar);
    }
  else
    my_put_error(ERR_ARGV);
  return (EXIT_SUCCESS);
}
Пример #2
0
void init_ui(char *name)
{
	init_curses();
	init_tree(name);
	init_lines();
	print_line(FILE(tree_root)->line);
	open_directory(tree_root);
	refresh_screen();
}
Пример #3
0
inline void init_hough(hough_t *hs)
{
	int i;

	hs->img_w = IMG_W;
	hs->img_h = IMG_H;
	hs->h = (int)(IMG_W*1.4142);
	hs->w = 180;
	hs->max = 0;

	for(i=0; i< (hs->w * hs->h); i++){ 	/* Clear the accumulator of previous usage */
		hs->accu[i] = 0;
	}

	if(hs->l){				/* Clear the lines too */
		clear_lines(hs->l);
	}
	init_lines(hs->l);			/* Allocate memory for the new lines */
}
Пример #4
0
int mipb_frac::run()
{
	bool targets=false;
	for (int user=0;user<lines;user++) {
		if (_rate_targets[user] != NOT_SET)
			targets=true;
	}	
	if (targets) {
		for (int user=0;user<lines;user++) {
			if (_rate_targets[user] == NOT_SET) 
				continue;
			_w_min[user]=0;
			_w_max[user]=1e-5;
			while(1) {
				reset_data();
				load();
				print_vector(_w,"_w");
                                print_vector(_b_total,"_b_total");
				//getchar();
				if (_b_total[user] > _rate_targets[user]) {
					_w_max[user] = _w[user];
				}
				else if (_b_total[user] < _rate_targets[user]) {
					_w_min[user] = _w[user];
				}
				if (abs(_b_total[user] - _rate_targets[user]) < _rate_tol) {
					printf("Converged on line %d\n",user);
					break;
				}
				_w[user] = (_w_max[user]+_w_min[user])/2;	
			}
		}
	}
	else
		load();
	init_lines();
	calculate_snr();
}
Пример #5
0
int multiuser_new::run()
{
        int tone,user,t_line,runs=0;
	FILE* fp[lines];
	bool last_run=false;
        reset_data();
	//fp[0]=fopen("line0_order.txt","w");
	//fp[1]=fopen("line1_order.txt","w");
        //calc_normalised_cost_matrix();
        //print_cost_matrix(0,10);
        //calc_delta_p_debug=true;
	for (int user=0;user<lines;user++) {
		printf("rate target on line %d is %d\n",user,b_target[user]);
		if (b_target[user]!=NOT_SET) {
			t_line=user;
		}
	}
	while((abs(b_target[t_line] - b_total[t_line]) > 5) || last_run) {
		reset_data();
		for (tone=0;tone<DMTCHANNELS;tone++) {
                	for(user=0;user<lines;user++) {
                        	calc_delta_p_cost(tone,user);
	                }
	        }
		//print_cost_matrix(0,DMTCHANNELS-1);
		while(1) {
			min_cost(&tone,&user);
			if(all_tones_full) {
				break;
			}
			b[tone][user]++;        // add bit to min cos tone
			b_total[user]++;
			total_bits++;
			update_power(tone,user);        //update power on tone
			//fprintf(fp[user],"%d %d\n",tone,total_bits);
			if (last_run && graph_loading)
				write_current_stats(tone,user);
			if (b[tone][user] == MAXBITSPERTONE) {
				F[tone][user]=1;
			}
			if (b_total[user] == b_target[user]) {
				freeze_user(user);
				if (last_run)
					printf("just froze user %d cos he got his target\n",user);
			}			
			for (int user=0;user<lines;user++)
				calc_delta_p_cost(tone,user);   // update delta_p on all lines for this tone
		}
		/*for (int user=0;user<lines;user++) {
			printf("b_%d = %d\n",user,b_total[user]);
		}*/
		//printf("w = %lf\n",w[t_line]);
		//getchar();
		if (last_run) {
			printf("this is the last run so setting last_run to false\n");
			last_run=false;
			break;
		}
		if (abs(b_target[t_line] - b_total[t_line]) < 5) {
			printf("Met the rate target, setting the last_run to true\n");
			last_run=true;
			continue;
		}
		if (b_total[t_line] > b_target[t_line]) {	// if rate > target_rate then this is the min weight
		//	printf("Rate is greater than target, so increase the weight and we have found the min weight\n");
			w_min[t_line]=w[t_line];		// set the min weight
			if (w_max[t_line] < 0) { 			// dont yet know the max weight
		//		printf("dont yet know the max weight so increase the weight\n");
				w[t_line]*=2;
			}
		}
		else {						// this is the max weight
		//	printf("Rate is less than target so decrease the weight and we have found the max weight\n");
			w_max[t_line]=w[t_line];
			if (w_min[t_line] < 0) {
		//		printf("dont yet know the min weight so decrease the weight\n");
				w[t_line]/=2;
			}
		}
		if (w_max[t_line] > 0 && w_min[t_line] > 0) {
			w[t_line] = (w_max[t_line]+w_min[t_line])/2;	
		//	printf("Currently bisecting, new weight is %lf\n",w[t_line]);
		}
	}
	//for (int user=0;user<lines;user++)
	//	fclose(fp[user]);
        init_lines();
        calculate_snr();
        set_loading_algo();
	return 0;
}
Пример #6
0
int multiuser_new::run_a()
{
        int tone,user,t_line,runs=0;
	FILE* fp;
	bool last_run=false;
        reset_data();
	//calc_ave_bits();
	//calc_ave_xtalk();
/*
	for (int user=0;user<lines;user++) {
		double max=0;
		int line=0;
		for (int xtalker=0;xtalker<lines;xtalker++) {
			if (xtalker==user)
				continue;
			if (ave_xtalk[user][xtalker] > max) {
				max = ave_xtalk[user][xtalker];
				line = xtalker;
			}
		}
		printf("Worst xtalker into line %d = line %d\n",user,line);
	}
*/
	//exit(0);
	//for (int user=0;user<lines;user++) {
	//	printf("rate target on line %d is %d\n",user,b_target[user]);
	//}
	do {
		iter_count++;
		reset_data();
		init_cost_matrix();
		//for (int user=0;user<lines;user++) {
		//	printf("w[%d] = %4.2lf\n",user,w[user]);
		//}
		while(1) {
			min_cost(&tone,&user);
			printf("Min tone/user was %d/%d\n",tone,user);
			//getchar();
			//if (tone == 115 && user == 1) {
			//	getchar();
			//}
			if(all_tones_full) {
				printf("All tones are full on iteration number %d\n",iter_count);
				break;
			}
			b[tone][user]++;        // add bit to min cos tone
			b_total[user]++;
			total_bits++;
			//printf("Added a bit to user %d tone %d\n",user,tone);
			//print_vector(cost[tone],"Costs on current tone");
			update_power(tone,user);        //update power on tone
			//print_vector(p[tone],"p on tone");
			//getchar();
			print_vector(b_total,"b_total");
			printf("total bits = %d\n",total_bits);
			print_vector(p_used,"p_used");
			if (!greedy) 
				update_wp();
			//print_vector(wp,"wp");
			//getchar();
			if (graph_loading)
				write_current_stats(tone,user);
			/*
			if (b[tone][user] == MAXBITSPERTONE) {
				F[tone][user]=1;
			}
			if (!rate_targets_off) {
				if (b_total[user] == b_target[user]) {
					freeze_user(user);
					printf("just froze user %d cos he got his target\n",user);
					printf("Power used by user %d when frozen = %lf\n",user,p_used[user]);
					init_cost_matrix();
					user_re_init[user]=true;
				}		
			}
			*/	
			/*for (int user=0;user<lines;user++) {
				if (user_frozen[user] == true && user_re_init[user] == false) {
					init_cost_matrix();	
					user_re_init[user]=true;
				}	
			}*/
			/*
			bool update=false;
			for (int user1=0;user1<lines;user1++) {
				if (wp[user1] > 1.1) {
					update=true;
					break;
				}
			}
			*/
			for (int user=0;user<lines;user++) {
				calc_delta_p(tone,user);   // update delta_p on all lines for this tone
				//cost[tone][user] = cf(tone,user);
			}
			//print_vector(_delta_p[tone][user],"Delta of adding another bit");
			for (int tone=0;tone<DMTCHANNELS;tone++) {
				for (int user=0;user<lines;user++) {
					cost[tone][user] = cf(tone,user);
				}
			}
			//print_vector(cost[tone],"New costs");
			//getchar();
		}
		for (int user=0;user<lines;user++) {
			printf("rate on line %d is %d\n",user,b_total[user]);
		}
		//getchar();
		calc_lost_bits();
		sort_lost_bits();
		print_lost_bits();
		if (0) {
			char tag[100];
			sprintf(tag,"iteration%d",iter_count);
			init_lines();
			calculate_snr();
			for (int user=0;user<lines;user++) {
				write_mw_stats(user,tag);
			}	
		}
		update_w();	
		//getchar();
	} while(!finished());
	if (all_rates_good()) {
		printf("All lines met their rate target\n");
	}
	else {
		double sum=0;
		for (int user=0;user<lines;user++) {
			sum+=pow(b_total[user]-b_target[user],2);
		}
		printf("Total distance from target = %lf\n",sqrt(sum));
	}
	//isb_optimise_p();
        init_lines();
        calculate_snr();
        set_loading_algo();
	printf("max lead = %6.4lf max lag = %6.4lf\n",max_lead,max_lag);
	if (graph_loading) {
		write_stats_totals();
	}
	return 0;
}
Пример #7
0
void wan_driver_init()
{
	//queue_init(&wan_queue, WAN_MSG_QUEUE_SIZE);
	init_buffer();
	init_lines();
}
Пример #8
0
static void init() {  
	init_connection();
  splash_window_show();
  init_lines();  
}
Пример #9
0
void win_textgrid_rearrange(window_t *win, grect_t *box, data_metrics_t *metrics)
{
    int ix, jx, oldval;
    int newwid, newhgt;
    window_textgrid_t *dwin = win->data;
    dwin->owner->bbox = *box;
    
    newwid = (((box->right - box->left) - 2*metrics->gridmarginx) / metrics->gridcharwidth);
    newhgt = (((box->bottom - box->top) - 2*metrics->gridmarginy) / metrics->gridcharheight);
    
    if (dwin->lines == NULL) {
        dwin->linessize = (newhgt+1);
        dwin->lines = (tgline_t *)malloc(dwin->linessize * sizeof(tgline_t));
        if (!dwin->lines)
            return;
        init_lines(dwin, 0, dwin->linessize, newwid);
    }
    else {
        if (newhgt > dwin->linessize) {
            oldval = dwin->linessize;
            dwin->linessize = (newhgt+1) * 2;
            dwin->lines = (tgline_t *)realloc(dwin->lines, 
                dwin->linessize * sizeof(tgline_t));
            if (!dwin->lines)
                return;
            init_lines(dwin, oldval, dwin->linessize, newwid);
        }
        if (newhgt > dwin->height) {
            /* Clear any new lines */
            for (jx=dwin->height; jx<newhgt; jx++) {
                tgline_t *ln = &(dwin->lines[jx]);
                for (ix=0; ix<ln->allocsize; ix++) {
                    ln->chars[ix] = ' ';
                    ln->styles[ix] = style_Normal;
                }
            }
        }
        for (jx=0; jx<newhgt; jx++) {
            tgline_t *ln = &(dwin->lines[jx]);
            if (newwid > ln->allocsize) {
                oldval = ln->allocsize;
                ln->allocsize = (newwid+1) * 2;
                ln->chars = (glui32 *)realloc(ln->chars, 
                    ln->allocsize * sizeof(glui32));
                ln->styles = (short *)realloc(ln->styles, 
                    ln->allocsize * sizeof(short));
                if (!ln->chars || !ln->styles) {
                    dwin->lines = NULL;
                    return;
                }
                for (ix=oldval; ix<ln->allocsize; ix++) {
                    ln->chars[ix] = ' ';
                    ln->styles[ix] = style_Normal;
                }
            }
        }
    }
    
    dwin->width = newwid;
    dwin->height = newhgt;

    dwin->alldirty = TRUE;
}
Пример #10
0
int osb::run()
{
	s_l=min_step;
	double prev_p_distance = DBL_MAX;
	//double min_p_distance = DBL_MAX;
	double p_distance = DBL_MAX;
	double prev_w_distance = DBL_MAX;
	//double min_w_distance = DBL_MAX;
	double w_distance = DBL_MAX;
	//double *best_l = new double [lines];
	//double *best_w = new double [lines];
	//bool first_run=true;
	bool reset_l=true;
	bool reset_w=true;
	while ( !(converged()) ) {		
		//psd->print_cache_size();		
		prev_p_distance = p_distance;	
		prev_w_distance = w_distance;
		if (reset_l) {
			prev_p_distance=DBL_MAX;
		}
		reset_l=false;
		if (reset_w) {
			prev_w_distance=DBL_MAX;
		}
		reset_w=false;
		for (int user=0;user<lines;user++) {
			last_rate[user]=current_rate[user];
			last_pow[user]=current_pow[user];
		}
		optimise_p();
		for (int user=0;user<lines;user++) {
			current_rate[user]=rate(user);
			current_pow[user]=tot_pow(user);
		}
		p_distance = calc_p_distance();
		printf("previous l distance was %lf\n",prev_p_distance);
		printf("current l distance is %lf\n",p_distance);
		printf("current  lstep is %lf\n",s_l);
		update_l();
/*	
		if (p_distance <= prev_p_distance) {
			if (p_distance <= min_p_distance) {
				min_p_distance=p_distance;	
				for (int user=0;user<lines;user++)
					best_l[user]=l[user];
			}
			update_l();
			s_l *= 2;
			printf("l step size increased to %lf\n",s_l);
		}
		else { 
			printf("Starting a new l trajectory\n");
			for (int user=0;user<lines;user++) 
				l[user] = best_l[user];
			p_distance=min_p_distance;
			s_l = min_step;
			reset_l=true;
			continue;
		}
*/
/*
		w_distance = calc_w_distance();
		printf("previous distance was %lf\n",prev_w_distance);
		printf("current distance is %lf\n",w_distance);
		printf("current step is %lf\n",s_w);
		if (w_distance <= prev_w_distance) {
			if (w_distance <= min_w_distance) {
				min_w_distance=w_distance;	
				for (int user=1;user<lines;user++)
					best_w[user]=w[user];
			}
			update_w();
			s_w *= 2;
			printf("w step size increased to %lf\n",s_w);
		}
		else { 
			printf("Starting a new w trajectory\n");
			for (int user=1;user<lines;user++) 
				w[user] = best_w[user];
			w_distance=min_w_distance;
			s_w = min_w_step;
			reset_w=true;
		}
*/
		/*
		if (!first_run) {
			int osc=0;
			for (int user=0;user<lines;user++) {
				if (pow_oscillating(user)) {
					osc++;
				}
				//printf("user %d's power is oscillating\n",user);
				if (osc==6) {
					s_l/=2;
					printf("Reducing step size to %lf\n",s_l);
					break;
				}
			}
		}
		*/
		//update_l();
		//update_w();
		//
		//getchar();
		//first_run=false;
	}
	init_lines();
	calculate_snr();
	return 0;
}