xptr_t st_write_split_state(struct st_tmp_trie * new_state) { struct state_descriptor dsc; struct st_page_header newpg; xptr_t parent_state = new_state->old_state; char * buf = new_state->buf2; size_t buflen = new_state->len2; int lower_edge = new_state->hint_edge; char * state = (char *) XADDR(parent_state); READ_PAGE(parent_state); state = read_state(state, &dsc); int n = dsc.edge_count; xptr_t * candidates = (xptr_t *) malloc(sizeof(xptr_t) * n); xptr_t c; xptr_t result; for (int i = 0; i < n; ++i) { struct state_descriptor tmp; read_state(state + dsc.pointers[i], &tmp); if ((tmp.flags & STATE_LONG_JUMP) > 0) { candidates[i] = tmp.long_jump; } else { candidates[i] = XNULL; } } c = select_candidate(candidates, n, buflen + sizeof(sptr_t)); //it's important to search candidate basing on full size of changes not only on string length. free(candidates); if (c == XNULL) { // U_ASSERT(false); st_markup_page(&newpg, 1, true); memcpy((char *) XADDR(newpg.page) + newpg.trie_offset, buf, buflen); newpg.data_end = newpg.trie_offset + buflen; st_write_page_header(&newpg); } else { c = GET_PAGE_ADDRESS(c); char * page_start = (char *) XADDR(c); st_read_page_header(c, &newpg); WRITE_PAGE(c); /* Add new trie to the end of the trie array */ newpg.trie_count++; memmove_ABd(page_start + newpg.trie_offset, page_start + newpg.data_end, sizeof(sptr_t)); newpg.tries[newpg.trie_count - 1] = newpg.data_end - newpg.trie_offset; newpg.data_end += sizeof(sptr_t); newpg.trie_offset += sizeof(sptr_t); memcpy(page_start + newpg.data_end, buf, buflen); newpg.data_end += buflen; st_write_page_header(&newpg); } result = newpg.page + newpg.trie_offset - sizeof(sptr_t); return result; }
void CVRP::constructGreedyRandomizedSolution(){ int n = 0; double waitTime = 0.0; int nVehi = deduce_nVehicles(0); vector<Route*> solution(nVehi, new Route); vector<int> route_capacity(nVehi, 0); vector<double> routes_times(nVehi, 0.0); vector<vector<Costumer*> > sol_candidates(solution.size(), vector<Costumer*> ()); dep.nVehicles = nVehi; for(int i = 0; i < solution.size(); i++){ solution[i] = new Route; } //Initialize the solution with nearby close clients init_solution(solution, routes_times, route_capacity, n); while(n != clients.size()){ //Update the list of candidates sol_candidates = update_list(solution, routes_times, n); for(int c = 0; c < sol_candidates.size(); c++){ sort(sol_candidates[c].begin(), sol_candidates[c].end(), saving_heuristic); } //shrink_routes(solution); select_candidate(solution, sol_candidates, routes_times, route_capacity, n); } double sum = 0.0; cout << "Solution size: " << solution.size() << endl; for(Route *r : solution){ for(Costumer *c : r->clients){ sum += c->cost; cout << c->id << " "; } cout << endl; } cout << sum << endl; cout << endl; /*for(int i = 0; i < solution.size(); i++){ solution[i]->clients.push_front(new Costumer(0, dep.coord,0,0,0,0)); solution[i]->clients.push_back(new Costumer(0, dep.coord,0,0,0,0)); }*/ sol = solution; for(Route *r : solution){ for(int i = 0; i < r->clients.size()-1; i++){ cout << r->clients[i]->id << ":" << r->clients[i]->arrTime + r->clients[i]->servTime << " " << r->clients[i+1]->id << ":" << r->clients[i+1]->dTime << endl; } cout << endl; } save(); }
void candidate_select_cb(void *ptr, int index) { uim_agent_context *ua = (uim_agent_context *)ptr; debug_printf(DEBUG_NOTE, "candidate_select_cb (index: %d)\n", index); #if !UIM_EL_USE_NEW_PAGE_HANDLING ua->cand->index = index; #else select_candidate(ua->context, ua->cand, index); #endif }
bool HangulInstance::candidate_key_event (const KeyEvent &key) { switch (key.code) { case SCIM_KEY_Return: case SCIM_KEY_KP_Enter: select_candidate (m_lookup_table.get_cursor_pos_in_current_page ()); break; case SCIM_KEY_KP_Subtract: m_lookup_table.cursor_up (); update_lookup_table (m_lookup_table); hangul_update_aux_string (); break; case SCIM_KEY_space: if (is_hanja_mode()) return false; case SCIM_KEY_KP_Add: m_lookup_table.cursor_down (); update_lookup_table (m_lookup_table); hangul_update_aux_string (); break; case SCIM_KEY_Page_Up: lookup_table_page_up(); break; case SCIM_KEY_Page_Down: case SCIM_KEY_KP_Tab: lookup_table_page_down(); break; case SCIM_KEY_h: if (is_hanja_mode()) return false; case SCIM_KEY_Left: if (m_factory->m_lookup_table_vertical) { lookup_table_page_up(); } else { m_lookup_table.cursor_up (); update_lookup_table (m_lookup_table); hangul_update_aux_string (); } break; case SCIM_KEY_l: if (is_hanja_mode()) return false; case SCIM_KEY_Right: if (m_factory->m_lookup_table_vertical) { lookup_table_page_down(); } else { m_lookup_table.cursor_down (); update_lookup_table (m_lookup_table); hangul_update_aux_string (); } break; case SCIM_KEY_k: if (is_hanja_mode()) return false; case SCIM_KEY_Up: if (m_factory->m_lookup_table_vertical) { m_lookup_table.cursor_up (); update_lookup_table (m_lookup_table); hangul_update_aux_string (); } else { lookup_table_page_up(); } break; case SCIM_KEY_j: if (is_hanja_mode()) return false; case SCIM_KEY_Down: if (m_factory->m_lookup_table_vertical) { m_lookup_table.cursor_down (); update_lookup_table (m_lookup_table); hangul_update_aux_string (); } else { lookup_table_page_down(); } break; case SCIM_KEY_Escape: delete_candidates (); break; case SCIM_KEY_1: case SCIM_KEY_2: case SCIM_KEY_3: case SCIM_KEY_4: case SCIM_KEY_5: case SCIM_KEY_6: case SCIM_KEY_7: case SCIM_KEY_8: case SCIM_KEY_9: select_candidate (key.code - SCIM_KEY_1); break; default: return !is_hanja_mode(); } return true; }