Пример #1
0
void time_printf(const char *fmt,
                 ...)
{
    if (INITIAL_TIME == 0)
        INITIAL_TIME = get_user_time();

    printf("[%10.2lf] ", get_user_time() - INITIAL_TIME);

    va_list args;
    va_start(args, fmt);
    vprintf(fmt, args);
    va_end(args);
    fflush(stdout);

    if(LOG_FILE)
    {
        fprintf(LOG_FILE, "[%10.2lf] ", get_user_time() - INITIAL_TIME);

        va_list args;
        va_start(args, fmt);
        vfprintf(LOG_FILE, fmt, args);
        va_end(args);

        fflush(LOG_FILE);
    }
}
Пример #2
0
int benchmark(int n_sets, struct LFreeSet2D *sets, double *rays,
              int algorithm)
{
    int rval = 0;

    log_info("Running benchmark...\n");

    double total_initial_time = get_user_time();
    stats_printf("cpu_time:\n");

    for (int j = 0; j < n_sets; j++)
    {
        log_debug("Set %d...\n", j);

        double set_initial_time = get_user_time();

        struct LFreeSet2D *set = &sets[j];
        double *pre_m = &PRE_M[j * 4];
        double center = CENTER[j];

        rval = LFREE_2D_print_set(set);
        abort_if(rval, "LFREE_2D_print_set failed");

        int wrong_answer = 0;

        rval = benchmark_set(algorithm, j, set, rays, pre_m, center, &wrong_answer);
        abort_if(rval, "benchmark_set failed");

        double set_duration = get_user_time() - set_initial_time;
        double avg = (set_duration / N_SAMPLES_PER_SET) * 1000;

        if(wrong_answer) avg = 1000000;

        stats_printf("  %d: %.8lf\n", j, avg);
        log_info("  %3d: %12.3lf ms\n", j, avg);
    }

    double total_duration = get_user_time() - total_initial_time;

    log_info("    %.3lf ms per set                     \n",
             total_duration / (n_sets * N_SAMPLES_PER_SET) * 1000);

    if(algorithm == ALGORITHM_MIP)
    {
        log_info("    %.3lf s spent on LP_create\n", MIP_TIME_CREATE);
        log_info("    %.3lf s spent on LP_optimize\n", MIP_TIME_OPTIMIZE);
    }

CLEANUP:
    return rval;
}
Пример #3
0
int GREEDY_BSEARCH_compute_bounds(int nrows,
                                  int nrays,
                                  const double *f,
                                  const double *rays,
                                  double *bounds)
{
    int rval = 0;

    struct LP lp;
    double e_upper = 2 * GREEDY_BIG_E;
    double e_lower = 0.0;

    int cplex_count = 0;
    double cplex_time = 0;

    int iteration_count = 0;

    double *x = 0;

    x = (double *) malloc((nrays + nrows) * sizeof(double));
    abort_if(!x, "could not allocate x");

    for (int i = 0; i < nrays; i++)
        bounds[i] = GREEDY_BIG_E;

    for (int it = 0;; it++)
    {
        abort_if(it > 2*nrays, "stuck in an infinite loop");

        log_verbose("Starting iteration %d...\n", it);

        iteration_count++;


        int solution_found = 0;
        int inner_count = 0;

        while (fabs(e_upper - e_lower) > GREEDY_MAX_GAP)
        {
            inner_count++;

            double e = (e_upper + e_lower) / 2;
            log_verbose("    e=%.12lf\n", e);

            rval = LP_open(&lp);
            abort_if(rval, "LP_open failed");

            rval = create_greedy_lp(nrows, nrays, f, rays, bounds, e, &lp);
            abort_if(rval, "create_greedy_lp failed");

            if_verbose_level
            {
                rval = LP_write(&lp, "greedy.lp");
                abort_if(rval, "LP_write failed");
            }

            int infeasible;
            cplex_count++;

            double initial_time = get_user_time();

            log_verbose("    Optimizing...\n");
            rval = LP_optimize(&lp, &infeasible);
            if (rval)
            {
                // Workaround for CPLEX bug. If CPLEX tell us that this problem
                // is unbounded, we disable presolve and try again.
                LP_free(&lp);
                LP_open(&lp);

                rval = create_greedy_lp(nrows, nrays, f, rays, bounds, e, &lp);
                abort_if(rval, "create_greedy_lp failed");

                LP_disable_presolve(&lp);

                rval = LP_optimize(&lp, &infeasible);
                abort_if(rval, "LP_optimize failed");
            }

            cplex_time += get_user_time() - initial_time;

            if (infeasible)
            {
                e_lower = e;
                log_verbose("    infeasible\n");
                if (e > GREEDY_BIG_E-1)
                {
                    LP_free(&lp);
                    goto OUT;
                }
            }
            else
            {
                log_verbose("    feasible\n");
                e_upper = e;
                solution_found = 1;

                rval = LP_get_x(&lp, x);
                abort_if(rval, "LP_get_x failed");
            }

            LP_free(&lp);
        }

        if (solution_found)
        {
            for (int j = 0; j < nrays; j++)
            {
                if (!DOUBLE_geq(x[nrows + j], 0.001)) continue;
                bounds[j] = fmin(bounds[j] * 0.99, e_lower * 0.99);
            }
        }

        log_verbose("    %d iterations  %12.8lf gap\n", inner_count, e_upper -
                    e_lower);

        e_lower = e_upper;
        e_upper = 2 * GREEDY_BIG_E;
    }

OUT:
    log_debug("    %6d IPs (%.2lfms per call, %.2lfs total)\n", cplex_count,
                cplex_time * 1000.0 / cplex_count, cplex_time);

    for(int i = 0; i < nrays; i++)
        abort_if(DOUBLE_iszero(bounds[i]), "bounds should be positive");

    if_verbose_level
    {
        time_printf("Bounds:\n");
        for (int k = 0; k < nrays; k++)
            time_printf("    %12.8lf  %12.8lf\n", k, bounds[k], 1 / bounds[k]);
    }

CLEANUP:
    if (x) free(x);
    return rval;
}
Пример #4
0
void main()
{   
  PINSEL0 |= 0X00050005;	 // selecting UART0 and UART1
  PINSEL1 |= 0X00080000;
  IO1DIR  |= 0X0FFF0000;	 //pins 1.16 to 1.23 output pins
  IO0DIR  |= 0X003E0C00;	 //port 0 rs and en as output
  IO0CLR   = 0X00FF0000;	
  
  IO0SET   = 0X0FF00400;
  IO0CLR   = BUZZER;

  //*************************************//
  //         Initialisations             //
  //*************************************//
  lcd_init();
  irq_init();
  uart_init();
  adc_init();
  //wdt_init();
  pwm5_init();
  timer1_init_interrupt();
  rtc_init_interrupt();
  
  //*************************************//
  //          Welcome Note               //
  //*************************************//
  lcd_line2_disp(&welcome_note1[0],0);
  lcd_line3_disp(&welcome_note2[0],6);
  ms_delay(50000);
  clrscr();
  lcd_line1_disp(&lcd_data_sys_chk[0],0);
  display_dots();
  display_dots();
  //*************************************//
  //  Displaying Static Messages		 //
  //*************************************//
  clrscr();
  default_page();
  U0IER = 0;

  rtc_get_time();
  lcd_line4_disp(&Uc_real_time[0],12);
  lcd_line4_disp(&Uc_set_user_time[0],0);

  wdt_init();
  while(1)
  {	
  
  	wdt_feed(0x03ffffff);
	rtc_get_time();
	lcd_line4_disp(&Uc_real_time[0],12);
	if(wdt_timeout == 1)
	{
		wdt_timeout = 0;
		lcd_line3_disp("WDEnable",12);
	}
	//*********************************************//
	//		ADC input value						   //
	//*********************************************//
	if(Uc_adc_time_out_flag == 1)
	{			
		Uc_adc_time_out_flag = 0;
		Ui_sample1 = adc1_getval();
		ms_delay(800);
		Ui_sample2 = adc1_getval();
		ms_delay(800);
		Ui_sample3 = adc1_getval();
		ms_delay(800);
		Ui_sample4 = adc1_getval();
		ms_delay(800);
		Ui_sample5 = adc1_getval();
		adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5, 1);
		temp_ctrl();
		lcd_line1_disp(&Uc_dec_arr[1],5);
		
		
					
		//*********Sending DATA to User desk*************//
		//uart0_send_string("\n\r ");
		uart0_send_byte((Ui_sample1 & 0xff));
		uart1_send_byte(0x7E);
		uart1_send_string(&Uc_dec_arr[1]);
		uart1_send_byte('\0');
		//**********************************************//
		
		Ui_sample1 = adc3_getval();
		ms_delay(900);
		Ui_sample2 = adc3_getval();
		ms_delay(900);
		Ui_sample3 = adc3_getval();
		ms_delay(900);
		Ui_sample4 = adc3_getval();
		ms_delay(900);
		Ui_sample5 = adc3_getval();
		ms_delay(750);
		Ui_sample6 = adc3_getval();
		ms_delay(750);
		Ui_sample7 = adc3_getval();
		ms_delay(750);
		Ui_sample8 = adc3_getval();
		ms_delay(750);
		Ui_sample9 = adc3_getval();
		Ui_sample6 = ((Ui_sample6 + Ui_sample7 + Ui_sample8 + Ui_sample9) / 4);
		Ui_sample5 = ((Ui_sample6 + Ui_sample5)/2);
		adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5 , 0);
		lcd_line3_disp(&Uc_dec_arr[1],5);
		
		//*********Sending DATA to User desk*************//
		uart1_send_string(&Uc_dec_arr[1]);
		//**********************************************//

	}


	//*********************************************//
	//   displaying Real Time & user Set Time      //
	//*********************************************//
	
	if(Uc_alrm == 1)
	{
		Uc_alrm = 2;
		pwm5_pulse_width(5000, 100);
	}
	/*
	else if(Uc_alrm == 3)
	{
		if(Uc_user_dwn_sec == 0)
		{
		   Uc_user_dwn_sec  = 59;

		   if( (Uc_user_dwn_min +  Uc_user_dwn_hr) != 0)
	   	 	{	
				Uc_user_dwn_min -= 1;
	   	   	}
		   Uc_set_user_time[3] = ((Uc_user_dwn_min / 10) + 0x30);
	   	   Uc_set_user_time[4] = ((Uc_user_dwn_min % 10) + 0x30);
		}
		if(Uc_user_dwn_min == 0)
		{
		   Uc_user_dwn_min  = 59;
	       if(Uc_user_dwn_hr != 0)
		   {
		   		Uc_user_dwn_hr -= 1;
		   }
	   	   Uc_set_user_time[0] = ((Uc_user_dwn_hr / 10) + 0x30);
	   	   Uc_set_user_time[1] = ((Uc_user_dwn_hr % 10) + 0x30);
		}
		Uc_set_user_time[6] = ((Uc_user_dwn_sec / 10) + 0x30);
		Uc_set_user_time[7] = ((Uc_user_dwn_sec % 10) + 0x30);
	 }

	 */
	//*********************************************//
	rtc_get_time();
	lcd_line4_disp(&Uc_real_time[0],12);
	lcd_line4_disp(&Uc_set_user_time[0],0);

	//*********************************************//
	//			key press on background  		   //
	//*********************************************//
	Uc_key_temp = get_key(0);
	if(Uc_key_temp == 'E')
	{
		Uc_key_temp = 0;
		get_user_time();
	}
	else if((Uc_key_temp == '.')&(Uc_alrm == 2))
	{
		Uc_key_temp = 0;
		Uc_alrm = 0;
		pwm_disable();
	}
	else if(Uc_key_temp == 'A')
	{
		clrscr();
		ms_delay(1000);
		lcd_line2_disp("Emergency Stop!",3);
		lcd_line4_disp("Cooling ON",5);
		IO0CLR = SSR_ON;
		IO0CLR = HEATER_ON;
		IO0SET = COOLER_ON;
		while(1);
	}
	else if(Uc_key_temp == 'D')
	{
		Uc_key_temp = 0;
		rtc_change_time();
	}

  }
}
Пример #5
0
/*
 * Computes the lifting coefficient of a ray by formulating the lifting
 * problem as a MIP.
 *
 * @param[in]  n_halfspaces  number of facets of the lattice-free set used
 * @param[in]  halfspaces    description of the lattice-free set used
 * @param[in]  ray           ray to lift
 * @param[out] value         lifting coefficient
 */
int LIFTING_2D_mip(int n_halfspaces,
                   const double *halfspaces,
                   const double *ray,
                   double *value)
{
    struct LP *lp = &LIFTING_2D_mip_lp;
    int rval = 0;

    double initial_time = get_user_time();

    rval = LIFTING_2D_mip_init();
    abort_if(rval, "LIFTING_2D_mip_init failed");

    rval = LP_create(lp, "lifting2d");
    abort_if(rval, "LP_create failed");

    rval = LP_new_col(lp, 1.0, 0.0, MILP_INFINITY, 'C');
    rval |= LP_new_col(lp, 0.0, -MILP_INFINITY, MILP_INFINITY, 'I');
    rval |= LP_new_col(lp, 0.0, -MILP_INFINITY, MILP_INFINITY, 'I');
    abort_if(rval, "LP_new_col failed");

    double rhs;
    char sense = 'G';
    int beg = 0;
    int ind[3] = {0, 1, 2};
    double val[3];

    val[0] = 1.0;

    for(int i = 0; i < n_halfspaces; i++)
    {
        double a0 = halfspaces[i * 2 + 0];
        double a1 = halfspaces[i * 2 + 1];

        rhs = a0 * ray[0] + a1 * ray[1];

        val[1] = -a0;
        val[2] = -a1;

        rval |= LP_add_rows(lp, 1, 3, &rhs, &sense, &beg, ind, val);
    }

    MIP_TIME_CREATE += get_user_time() - initial_time;

    abort_if(rval, "LP_add_rows failed");

    int infeasible;

    initial_time = get_user_time();

    rval = LP_optimize(lp, &infeasible);
    abort_if(rval, "LP_optimize failed");
    abort_if(infeasible, "LIFTING_2D_mip infeasible");

    MIP_TIME_OPTIMIZE += get_user_time() - initial_time;

    double obj;

    rval = LP_get_obj_val(lp, &obj);
    abort_if(rval, "LP_get_obj_val failed");

    *value = obj;

CLEANUP:
    LP_destroy(lp);
    return (rval);
}