double _MDLtotal(Stack *Opt, Stack *C){ int r = Opt->idx + C->idx; int m = mSegment(Opt) + mSegment(C); double cost = MDLSegment(Opt) + MDLSegment(C); double costT = cost + log_s(r) + log_s(m) + m*log_2(r) + FB*r*r; fprintf(stdout, "%d %d %.0f \n", r, m, costT); return costT; }
void layout_boxes(Layouter *layouter) { log_s(L_Layouter, "init\n"); u32 passes = 0; b32 moved_rect = true; while (moved_rect && passes < MAX_PASSES) { log_s(L_Layouter, ">\n"); moved_rect = false; for (u32 subject_index = 0; subject_index < layouter->next_free; ++subject_index) { log_s(L_Layouter, " "); Rectangle *current_subject = layouter->rects + subject_index; for (u32 test_index = 0; test_index < layouter->next_free; ++test_index) { Rectangle *test = layouter->rects + test_index; if (test != current_subject) { if (overlaps(*current_subject, *test)) { log_s(L_Layouter, " "); moved_rect = true; Rectangle overlap = get_overlap(*current_subject, *test); r32 h_dist = overlap.end.x - overlap.start.x; r32 v_dist = overlap.end.y - overlap.start.y; V2 direction = vector_direction_or_1(get_center(*test) - get_center(*current_subject)); if (h_dist < v_dist) { *test += (V2){h_dist, 0} * direction.x; } else { *test += (V2){0, v_dist} * direction.y; } } else { log_s(L_Layouter, "# "); } }
int main(void) { setup(); while(1) { _delay_ms(1000); //for (byte scroll=0;scroll<4;scroll++){ // glcd.setIndicator(2, GLCD_INDICATOR_2); // glcd.command(GLCD_CMD_INITIAL_DISPLAY_LINE(scroll)); glcd.setCursor(25,5*8); //glcd.print(F("Hello world!")); glcd.drawText_P(8*0,14,&fixed_font,PSTR("Arduino Pong")); _delay_ms(2000); //for (byte scroll=0;scroll<49;scroll++){ // glcd.command(GLCD_CMD_INITIAL_DISPLAY_LINE(scroll)); // _delay_ms(150); //} log_s("ALIVE! \n"); //_delay_ms(150); // log_s("ALIVE! \n"); // _delay_ms(1000); // */ // log_s("ALIVE! \n"); // _delay_ms(500); // Wait for startup! } }
int _findOptSeedLen(SegBox *Sx){ SegBox *s0= _getS("",""); SegBox *s1= _getS("",""); int iter1, iter2; double min=INF, prev=INF, pprev=INF; int len = FB; int minlen = Sx->Sb[FindMinStEd(Sx)].len; int maxlen = (int)ceil(ws->lmax*LM); int optlen= minlen; while((double)len <= maxlen && len <= minlen){ int lm = Sx->len; double cost = _findCentroid(Sx, s0, s1, NSAMPLE, len); cost += len*log_s(MINK); #if(DBG) fprintf(stderr, "%d %f\n", len, cost); #endif //if(cost> prev) break; prev = cost; optlen = len; if(pprev < prev && pprev < cost) {optlen=len/(2*2); break;} pprev=prev; prev = cost; if(cost< min){min = cost; optlen = len;}//if /// next length: current*2, i.e., 2^x; len*=2; }//while #if(DBG) fprintf(stderr, "optimal minimum length: %d\n", optlen); #endif _releaseS(s0); _releaseS(s1); return optlen; }
void uiblock_setparent(uiblock_t *block,uiblock_t *parent) { if (block!=parent) { if (block->parent==NULL) { uint16_t childpos=0; if (parent->children==NULL) parent->children=malloc(sizeof(uiblock_t *)); else { while ((childpos<parent->children_count)&&(parent->children[childpos]!=NULL)) childpos++; if (childpos==parent->children_count) { parent->children_count++; parent->children=realloc(parent->children,sizeof(uiblock_t *)*parent->children_count); } } parent->children[childpos]=block; block->parent=parent; } else log_s("WARNING: parent already set\n"); } else log_s("WARNING: attempt to self parent"); }
/** * The main function. */ int main(void) { /* Initialization */ init_qfly(); log_s("receiver initialization ... ok\n"); /* Our loop */ while (1) { /* Wait 100ms */ _delay_ms(100); #ifdef UART_AVAILABLE if (uart_rx_ready()) { uart_tx("Echo: "); uart_tx(uart_rx()); uart_tx("\n"); } #endif /* UART_AVAILABLE */ } /* Finally. (Never ever) */ return 0; }
void setup(){ // cli(); // Turn all interrupts off! sei(); // Turn interrupts on. _delay_ms(4000); // Wait for startup! // SPI CS INIT - set all CS lines high! DDR_RFM_CS |= (1 << BIT_RFM_CS); // Set RFM12B CS to output PORT_RFM_CS |= (1 << BIT_RFM_CS); // Pull RFM12B CS high DDR_MEM_SS |= (1 << BIT_MEM_SS); // Set memory CS to output PORT_MEM_SS |= (1 << BIT_MEM_SS); // Pull memory CS high DDR_ETH_SS |= (1 << BIT_ETH_SS); // Set Ethernet CS to output PORT_ETH_SS |= (1 << BIT_ETH_SS); // Pull Ethernet CS high // SPI CS INIT - set all CS lines high! // SET ALL LED TO OUTPUT LED_433RECEIVE_DDR |= (1 << LED_433RECEIVE_BIT); // set output LED_433SEND_DDR |= (1 << LED_433SEND_BIT); // set output LED_868RECEIVE_DDR |= (1 << LED_868RECEIVE_BIT); // set output LED_868SEND_DDR |= (1 << LED_868SEND_BIT); // set output LED_DCF77_DDR |= (1 << LED_DCF77_BIT); // set output LED_LCD_DDR |= (1 << LED_LCD_BIT); // set output // SET ALL LED TO OUTPUT // TEST LEDS blinkAllLeds(true); _delay_ms(1000); blinkAllLeds(false); _delay_ms(500); blinkAllLeds(true); _delay_ms(1000); blinkAllLeds(false); // TEST LEDS /* Initialize UART */ uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU)); /* Initialize RFM12B*/ rf12_initialize(NODEID, RF12_868MHZ, NETWORKID); // see http://tools.jeelabs.org/rfm12b rf12_control(0xC040); // set low-battery level to 2.2V i.s.o. 3.1V // Initialize library millis_init(); LED_LCD_PORT |= (1 << LED_LCD_BIT); // set output /* GLCD_IO_PIN_A0_1(); GLCD_IO_PIN_RW_1(); GLCD_IO_PIN_E_1(); GLCD_IO_DATA_DIR_OUTPUT(); GLCD_IO_DATA_OUTPUT(0b11111111); */ //glcd.init(); //glcd.setFont(&proportional_font); //glcd.clearDisplay(); //uint8_t ret = glcd.drawPixel(GLCD_INDICATOR_2, 48, 2); //uart0_putc(ret); //glcd.drawLine(1, 1, 100,100, GLCD_COLOR_FILLED); glcd.init(); glcd.setFont(&proportional_font); glcd.clearDisplay(); log_s("ISA GATEWAY \n\r"); log_s("STARTUP OK! \n\r"); }
double costHMM(int k, int d){ double fB = (double) FB; double cost = (double) fB * (k + k*k + 2*k*d) + log_s(k); return cost; }
void parse(Maze *maze, Functions *functions, Memory *memory, const char *filename) { clear_maze(maze); zero(functions, Functions); maze->tree.bounds = (Rectangle){(V2){0, 0}, (V2){10000, 10000}}; u32 x = 0; u32 y = 0; u32 fd = open(filename, O_RDONLY); if (fd == -1) { printf("Failed to open file.\n"); exit(1); } struct stat sb; if (fstat(fd, &sb) == -1) { printf("Failed to open file.\n"); exit(1); } char *file = (char *)mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (file == MAP_FAILED) { printf("Failed to open file.\n"); exit(1); } char cell_str[2] = {}; char *f_ptr = file; char *f_end = f_ptr + sb.st_size; while (f_ptr < f_end) { cell_str[0] = f_ptr[0]; cell_str[1] = f_ptr[1]; Cell new_cell = {}; new_cell.type = CELL_NULL; f_ptr = parse_cell(maze, functions, cell_str, f_ptr, f_end, &new_cell); if (new_cell.type != CELL_NULL) { Cell *cell = get_cell(maze, x, y, memory); cell->type = new_cell.type; cell->pause = new_cell.pause; cell->function_index = new_cell.function_index; cell->name[0] = cell_str[0]; cell->name[1] = cell_str[1]; log_s(L_Parser, "%.2s ", cell_str); ++x; } else { if (cell_str[0] == '\n') { x = 0; ++y; log_s(L_Parser, "\n"); } f_ptr += 1; } } log_s(L_Parser, "\n"); if (munmap((void *)file, sb.st_size) != 0) { printf("Error unmapping file."); } if (close(fd) != 0) { printf("Error while closing file descriptor."); } }