OPTION * create_word_prediction_seq(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, OPTION *opt, int do_free_partials) { ASSERT(ap->input_offset == 1 || ap->input_offset == 0); int pos = sent->pos[opt->period + ap->input_offset]; int feat = sent->feat_out[opt->period + ap->input_offset]; int word = sent->word_out[opt->period + ap->input_offset]; OPTION *new_opt = create_option(SYNT_STEP, 0, opt->previous_act, pos, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, NULL, NULL, &mp->out_link_feat[pos], mp->pos_info_out.feat_infos[pos].num); set_links(ap, mp, new_opt, sent); new_opt = create_option(SYNT_STEP, 0, opt->previous_act, feat, new_opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, NULL, NULL, &mp->out_link_word[pos][feat], mp->pos_info_out.feat_infos[pos].word_infos[feat].num); set_links(ap, mp, new_opt, sent); new_opt = create_option(SYNT_STEP, 1, SHIFT, word, new_opt, opt->period + 1, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->pt), &(opt->ps)); st_push(&new_opt->stack, new_opt->queue); st_push(&new_opt->srl_stack, new_opt->queue); new_opt->queue++; set_links(ap, mp, new_opt, sent); return new_opt; }
OPTION *root_prediction(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent) { //opt to predict shift STACK st; st.size = 0; STACK srl_st; srl_st.size = 0; OPTION *opt = create_option(SRL_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM); set_links(ap, mp, opt, sent); return opt; }
OPTION* _action_srl_red(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, int do_free_partials, OPTION *opt) { //create sequence of reduce operation //update queue and stack opt = create_option(SRL_STEP, 1, SRL_RED, SRL_RED, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); st_pop(&opt->srl_stack); set_links(ap, mp, opt, sent); return opt; }
OPTION* _action_synt_flip(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, int do_free_partials, OPTION *opt) { opt = create_option(SYNT_STEP, 1, FLIP, FLIP, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); int s = st_pop(&opt->stack); int s_under = st_pop(&opt->stack); st_push(&opt->stack, s); st_push(&opt->stack, s_under); set_links(ap, mp, opt, sent); return opt; }
// do_fork - parent process for a new child process // 1. call alloc_proc to allocate a proc_struct // 2. call setup_kstack to allocate a kernel stack for child process // 3. call copy_mm to dup OR share mm according clone_flag // 4. call wakup_proc to make the new child process RUNNABLE int do_fork(uint32_t clone_flags, uintptr_t stack, struct trapframe *tf) { int ret = -E_NO_FREE_PROC; struct proc_struct *proc; if (nr_process >= MAX_PROCESS) { goto fork_out; } ret = -E_NO_MEM; if ((proc = alloc_proc()) == NULL) { goto fork_out; } proc->parent = current; list_init(&(proc->thread_group)); assert(current->wait_state == 0); assert(current->time_slice >= 0); proc->time_slice = current->time_slice / 2; current->time_slice -= proc->time_slice; if (setup_kstack(proc) != 0) { goto bad_fork_cleanup_proc; } if (copy_sem(clone_flags, proc) != 0) { goto bad_fork_cleanup_kstack; } if (copy_fs(clone_flags, proc) != 0) { goto bad_fork_cleanup_sem; } if ( copy_signal(clone_flags, proc) != 0 ) { goto bad_fork_cleanup_fs; } if ( copy_sighand(clone_flags, proc) != 0 ) { goto bad_fork_cleanup_signal; } if (copy_mm(clone_flags, proc) != 0) { goto bad_fork_cleanup_sighand; } if (copy_thread(clone_flags, proc, stack, tf) != 0) { goto bad_fork_cleanup_sighand; } bool intr_flag; local_intr_save(intr_flag); { proc->pid = get_pid(); proc->tid = proc->pid; hash_proc(proc); set_links(proc); if (clone_flags & CLONE_THREAD) { list_add_before(&(current->thread_group), &(proc->thread_group)); proc->gid = current->gid; }else{ proc->gid = proc->pid; } } local_intr_restore(intr_flag); wakeup_proc(proc); ret = proc->pid; fork_out: return ret; bad_fork_cleanup_sighand: put_sighand(proc); bad_fork_cleanup_signal: put_signal(proc); bad_fork_cleanup_fs: put_fs(proc); bad_fork_cleanup_sem: put_sem_queue(proc); bad_fork_cleanup_kstack: put_kstack(proc); bad_fork_cleanup_proc: kfree(proc); goto fork_out; }
int main (int argc, char *argv[]) { ServerData app; GError *error = NULL; GOptionContext *context = NULL; GstBus *bus = NULL; int error_flag = 0; GOptionEntry entries [] = { { "interface", 'i', 0, G_OPTION_ARG_STRING, &net_if, "network interface", NULL}, { "port", 'p', 0, G_OPTION_ARG_INT, &port, "port number", NULL }, { "fileuri", 'f', 0, G_OPTION_ARG_STRING, &uri, "URI to stream", "URI (<protocol>://<location>)"}, { NULL } }; context = g_option_context_new ("- simple tcp streaming server"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { fprintf (stderr, "option parsing failed: %s\n", error->message); error_flag = 1; } error_flag = check_args (); if (error_flag) { fprintf (stderr, "Exiting...\n"); return EXIT_FAILURE; } addr = if_addr (net_if); if (addr == NULL) { fprintf (stderr, "There is no ip address bound to the interface %s\n", net_if); return EXIT_FAILURE; } error_flag = init (&app); if (!error_flag) error_flag = set_links (&app); if (error_flag) { fprintf (stderr, "Exiting...\n"); return EXIT_FAILURE; } g_object_set (GST_OBJECT (app.source), "uri", uri, NULL); g_object_set (GST_OBJECT (app.muxer), "streamable", TRUE, NULL); g_object_set (GST_OBJECT (app.sink), "host", addr, NULL); g_object_set (GST_OBJECT (app.sink), "port", port, NULL); g_signal_connect (app.source, "pad-added", G_CALLBACK (pad_added), &app); bus = gst_pipeline_get_bus (GST_PIPELINE (app.pipeline)); gst_bus_add_watch (bus, bus_call, &app); fprintf (stdout, "Preparing the streaming of: %s\n" "Network Interface: %s\n" "Server IP: %s\n" "Server port: %d\n", uri, net_if, addr, port); fprintf (stdout, "Press 'q' to stop streaming and quit\n"); free (addr); gst_element_set_state (GST_ELEMENT (app.pipeline), GST_STATE_PLAYING); g_main_loop_run (app.loop); gst_element_set_state (GST_ELEMENT (app.pipeline), GST_STATE_NULL); gst_object_unref (GST_OBJECT(bus)); gst_object_unref (GST_OBJECT (app.pipeline)); fprintf (stdout, "All done\n"); return EXIT_SUCCESS; }
// This routine assumes the sentinel points have already been added, and processes points in order GEODE_NEVER_INLINE static Ref<MutableTriangleTopology> deterministic_exact_delaunay(RawField<const Perturbed2,VertexId> X, const bool validate) { const int n = X.size()-3; const auto mesh = new_<MutableTriangleTopology>(); IntervalScope scope; // Initialize the mesh to a Delaunay triangle containing the sentinels at infinity. mesh->add_vertices(n+3); mesh->add_face(vec(VertexId(n+0),VertexId(n+1),VertexId(n+2))); if (self_check) { mesh->assert_consistent(); assert_delaunay("self check 0: ",mesh,X); } // The randomized incremental construction algorithm uses the history of the triangles // as the acceleration structure. Specifically, we maintain a BSP tree where the nodes // are edge tests (are we only the left or right of an edge) and the leaves are triangles. // There are two operations that modify this tree: // // 1. Split: A face is split into three by the insertion of an interior vertex. // 2. Flip: An edge is flipped, turning two triangles into two different triangles. // // The three starts out empty, since one triangle needs zero tests. Array<Node> bsp; // All BSP nodes including leaves bsp.preallocate(3*n); // The minimum number of possible BSP nodes Field<Vector<int,2>,FaceId> face_to_bsp; // Map from FaceId to up to two BSP leaf points (2*node+(right?0:1)) face_to_bsp.flat.preallocate(2*n+1); // The exact maximum number of faces face_to_bsp.flat.append_assuming_enough_space(vec(0,-1)); // By the time we call set_links, node 0 will be valid if (self_check) check_bsp(*mesh,bsp,face_to_bsp,X); // Allocate a stack to simulate recursion when flipping non-Delaunay edges. // Invariant: if edge is on the stack, the other edges of face(edge) are Delaunay. // Since halfedge ids change during edge flips in a corner mesh, we store half edges as directed vertex pairs. Array<Tuple<HalfedgeId,Vector<VertexId,2>>> stack; stack.preallocate(8); // Insert all vertices into the mesh in random order, maintaining the Delaunay property for (const auto i : range(n)) { const VertexId v(i); check_interrupts(); // Search through the BSP tree to find the containing triangle const auto f0 = bsp_search(bsp,X,v); const auto vs = mesh->vertices(f0); // Split the face by inserting the new vertex and update the BSP tree accordingly. mesh->split_face(f0,v); const auto e0 = mesh->halfedge(v), e1 = mesh->left(e0), e2 = mesh->right(e0); assert(mesh->dst(e0)==vs.x); const auto f1 = mesh->face(e1), f2 = mesh->face(e2); const int base = bsp.extend(3,uninit); set_links(bsp,face_to_bsp[f0],base); bsp[base+0] = Node(vec(v,vs.x),base+2,base+1); bsp[base+1] = Node(vec(v,vs.y),~f0.id,~f1.id); bsp[base+2] = Node(vec(v,vs.z),~f1.id,~f2.id); face_to_bsp[f0] = vec(2*(base+1)+0,-1); face_to_bsp.flat.append_assuming_enough_space(vec(2*(base+1)+1,2*(base+2)+0)); face_to_bsp.flat.append_assuming_enough_space(vec(2*(base+2)+1,-1)); if (self_check) { mesh->assert_consistent(); check_bsp(*mesh,bsp,face_to_bsp,X); } // Fix all non-Delaunay edges stack.copy(vec(tuple(mesh->next(e0),vec(vs.x,vs.y)), tuple(mesh->next(e1),vec(vs.y,vs.z)), tuple(mesh->next(e2),vec(vs.z,vs.x)))); if (self_check) assert_delaunay("self check 1: ",mesh,X,Tuple<>(),true); while (stack.size()) { const auto evs = stack.pop(); auto e = mesh->vertices(evs.x)==evs.y ? evs.x : mesh->halfedge(evs.y.x,evs.y.y); if (e.valid() && !is_delaunay(*mesh,X,e)) { // Our mesh is linearly embedded in the plane, so edge flips are always safe assert(mesh->is_flip_safe(e)); e = mesh->unsafe_flip_edge(e); GEODE_ASSERT(is_delaunay(*mesh,X,e)); // Update the BSP tree for the triangle flip const auto f0 = mesh->face(e), f1 = mesh->face(mesh->reverse(e)); const int node = bsp.append(Node(mesh->vertices(e),~f1.id,~f0.id)); set_links(bsp,face_to_bsp[f0],node); set_links(bsp,face_to_bsp[f1],node); face_to_bsp[f0] = vec(2*node+1,-1); face_to_bsp[f1] = vec(2*node+0,-1); if (self_check) { mesh->assert_consistent(); check_bsp(*mesh,bsp,face_to_bsp,X); } // Recurse to successor edges to e const auto e0 = mesh->next(e), e1 = mesh->prev(mesh->reverse(e)); stack.extend(vec(tuple(e0,mesh->vertices(e0)), tuple(e1,mesh->vertices(e1)))); if (self_check) assert_delaunay("self check 2: ",mesh,X,Tuple<>(),true); } } if (self_check) { mesh->assert_consistent(); assert_delaunay("self check 3: ",mesh,X); } } // Remove sentinels for (int i=0;i<3;i++) mesh->erase_last_vertex_with_reordering(); // If desired, check that the final mesh is Delaunay if (validate) assert_delaunay("delaunay validate: ",mesh,X); // Return the mesh with the sentinels removed return mesh; }
//processes sentence and creates derivations //returns tail of the derivation OPTION *get_derivation(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, int do_free_partials) { /* if (ap->intern_synt_deproj == DEPROJ_EXHAUSTIVE && !ap->is_synt_early_reduce) { fprintf(stderr, "Error: exhaustive internal syntactic projectivization with late reduce strategy is not supported\n"); exit(EXIT_FAILURE); } if (ap->intern_srl_deproj == DEPROJ_EXHAUSTIVE && !ap->is_srl_early_reduce) { fprintf(stderr, "Error: exhaustive internal SRL projectivization with late reduce strategy is not supported\n"); exit(EXIT_FAILURE); } */ //Debug // printf("Next sentence ============\n"); ASSERT(ap->input_offset == 0 || ap->input_offset == 1); STACK st; st.size = 0; STACK srl_st; srl_st.size = 0; //OPTION *head = create_option(SYNT_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM); OPTION *head = create_option(SRL_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM); ///st_push(&head->srl_stack, 0); //JH allow 0 as an SRL argument set_links(ap, mp, head, sent); ///printf("new sentence\n");/// OPTION *opt = head; while (opt->queue != sent->len + 1) { //get next possible actions ACTION_SET as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); //===================== SYNTAX ====================================================== if (ap->is_synt_early_reduce && as.acts[RED]) { int s = st_peek(&opt->stack); if (everything_complete(opt->pt, sent, s)) { if (ap->parsing_mode != 3 || sent->head[s] != 0 || sent->deprel[s] != ROOT_DEPREL) { opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("RED\n"); continue; } } } //check LA if (as.acts[LA]) { int d = st_peek(&opt->stack); int h = opt->queue; if (sent->head[d] == h) { //create sequence of LA operations //update queue and stack opt = create_option(SYNT_STEP, 0, opt->previous_act, LA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_la_label, mp->deprel_num); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); //opt->previous_option->pt = NULL; set_links(ap, mp, opt, sent); opt = create_option(SYNT_STEP, 1, LA, sent->deprel[d], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); //opt->previous_option->pt = NULL; pt_add_link(opt->pt, h, d, sent->deprel[d]); opt->pt->right_connections_num[d]++; if (ap->intern_synt_deproj == DEPROJ_NO) { st_pop(&opt->stack); } else { // Do Nothing!!! } set_links(ap, mp, opt, sent); //DEBUG //printf("LA\n"); continue; } } //check RA if (as.acts[RA]) { int d = opt->queue; int h = st_peek(&opt->stack); //when agrees if (sent->head[d] == h) { //means if stack is not empty or we can make RA with empty stack if (h != 0 || (ap->parsing_mode >= 3 && sent->deprel[d] != ROOT_DEPREL // can do only once && opt->pt->nodes[d].deprel == ROOT_DEPREL)) { //create sequence of RA operations //update queue and stack opt = create_option(SYNT_STEP, 0, opt->previous_act, RA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_ra_label, mp->deprel_num); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SYNT_STEP, 1, RA, sent->deprel[d], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); pt_add_link(opt->pt, h, d, sent->deprel[d]); if (h != 0) { opt->pt->right_connections_num[h]++; } set_links(ap, mp, opt, sent); //DEBUG //printf("RA\n"); continue; } } } // check FLIP if (as.acts[FLIP] && ap->intern_synt_deproj == DEPROJ_EXHAUSTIVE) { int s = st_peek(&opt->stack); int s_already_conns = opt->pt->right_connections_num[s]; int s_under = st_look(&opt->stack, 1); int s_under_already_conns = opt->pt->right_connections_num[s_under]; int top_is_usl = (sent->synt_right_degree[s] == s_already_conns); int under_top_is_usl = (sent->synt_right_degree[s_under] == s_under_already_conns); if (ap->is_synt_early_reduce || (!top_is_usl && !under_top_is_usl) ) { // s_under will be active earlier than s if (lexicograph_ignore_double_entries_comp( sent->synt_right_indices[s_under] + s_under_already_conns, sent->synt_right_degree[s_under] - s_under_already_conns, sent->synt_right_indices[s] + s_already_conns, sent->synt_right_degree[s] - s_already_conns) < 0) { //create sequence of reduce operation //update queue and stack opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt); //DEBUG printf("(SYNT) FLIP\n"); continue; } } else { // if a top word can be reduce from the top if (top_is_usl) { int first_usf = get_useful(&opt->stack, 1, opt->pt->right_connections_num, sent->synt_right_degree); if (first_usf > 0) { // first 'useful' word in the stack should be attached to front of queue -- start remioving useless words // next words will be removed on the next rounds int next_connection = sent->synt_right_indices[first_usf][opt->pt->right_connections_num[first_usf]]; if (next_connection == opt->queue) { ASSERT(as.acts[RED]); opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("RED\n"); continue; } } } else { // if int second_usf = get_useful(&opt->stack, 1, opt->pt->right_connections_num, sent->synt_right_degree); ASSERT(second_usf != s_under); if (second_usf > 0) { int second_usf_already_conns = opt->pt->right_connections_num[second_usf]; if (lexicograph_ignore_double_entries_comp( sent->synt_right_indices[second_usf] + second_usf_already_conns, sent->synt_right_degree[second_usf] - second_usf_already_conns, sent->synt_right_indices[s] + s_already_conns, sent->synt_right_degree[s] - s_already_conns) < 0) { opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt); as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); ASSERT(as.acts[RED]); opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); // DEBUG printf("FLIP, followed by RED\n"); //printf("RED, preceded by FLIP\n"); continue; } } } // !top_is_usl } // !ap->is_synt_early_reduce } // FLIP //check SWITCH if (as.acts[SWITCH]) { int q = opt->queue; if (left_part_complete(opt->pt, sent, q)) { //if atached to root with not ROOT_DEPREL and parsing_mode >= 3 then RA, not SHIFT should be peformed //option sent->deprel[q] == opt->pt->nodes[q]->deprel - relates to RA- + SHIFT sequence and means that RA- is actually preformed //and q is already attached if (sent->head[q] != 0 || ap->parsing_mode < 3 || (ap->parsing_mode >= 3 && (sent->deprel[q] == ROOT_DEPREL || sent->deprel[q] == opt->pt->nodes[q].deprel))) { opt = create_option(SRL_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); /* opt = create_option(SYNT_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); */ TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); //DEBUG //printf("SWITCH\n"); continue; } } } //check RED if (!ap->is_synt_early_reduce && as.acts[RED]) { int s = st_peek(&opt->stack); if (everything_complete(opt->pt, sent, s)) { if (ap->parsing_mode != 3 || sent->head[s] != 0 || sent->deprel[s] != ROOT_DEPREL) { opt = _action_synt_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("RED\n"); continue; } } } // check FLIP if (as.acts[FLIP] && ap->intern_synt_deproj != DEPROJ_EXHAUSTIVE) { opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt); //DEBUG printf("(SYNT) FLIP\n"); continue; } //===================== WORD PREDICTION ============================================= if (as.acts[SHIFT]) { //create sequence of shift operation //update queue and stack opt = create_option(SYNT_STEP, 0, opt->previous_act, SHIFT, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_pos, get_pos_out_num()); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_word_prediction_seq(ap, mp, sent, opt, do_free_partials); //DEBUG //printf("SHIFT\n"); continue; } //===================== SRL ====================================================== if (ap->is_srl_early_reduce && as.acts[SRL_RED]) { int srl_s = st_peek(&opt->srl_stack); if (srl_everything_complete(opt->ps, sent, srl_s)) { opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); //DEBUG // printf("SRL_RED\n"); continue; } } //check SRL_LA int q_bank = sent->bank[opt->queue]; ///if (q_bank >= 0)/// /// printf("srl_la 0: %d %d; %d %d\n", q_bank, as.acts[SRL_LA[q_bank]], st_peek(&opt->srl_stack), opt->queue);/// if (q_bank >= 0 && as.acts[SRL_LA[q_bank]]) { int d = st_peek(&opt->srl_stack); int h = opt->queue; int role = next_srl_role(0, sent, h, d); ///printf("srl_la 1: %d %d %d\n", d, h, role);/// if (role >= 0) { int i = 0; for (; role >= 0; role = next_srl_role(i, sent, h, d)) { i++; //create sequence of SRL_LA operations //update queue and stack opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_LA[q_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_la_label[q_bank], mp->role_num[q_bank]); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SRL_STEP, 1, SRL_LA[q_bank], role, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); ps_add_link(opt->ps, h, d, role); opt->ps->right_connections_num[d]++; set_links(ap, mp, opt, sent); //DEBUG //printf("SRL_LA[%d]\n", q_bank); } continue; } } q_bank = -1; //check SRL_RA int s_bank = sent->bank[st_peek(&opt->srl_stack)]; if (s_bank >= 0 && as.acts[SRL_RA[s_bank]]) { int d = opt->queue; int h = st_peek(&opt->srl_stack); int role = next_srl_role(0, sent, h, d); ///printf("srl_ra: %d %d %d\n", d, h, role);/// //when agrees if (role >= 0) { int i = 0; for (; role >= 0; role = next_srl_role(i, sent, h, d)) { ASSERT(i == 0); i++; //create sequence of RA operations //update queue and stack opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_RA[s_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_ra_label[s_bank], mp->role_num[s_bank]); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SRL_STEP, 1, SRL_RA[s_bank], role, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); ps_add_link(opt->ps, h, d, role); opt->ps->right_connections_num[h]++; set_links(ap, mp, opt, sent); //DEBUG //printf("SRL-RA[%d]\n", s_bank); } // role continue; } } if (as.acts[SRL_FLIP] && ap->intern_srl_deproj == DEPROJ_EXHAUSTIVE) { int srl_s = st_peek(&opt->srl_stack); int srl_s_already_conns = opt->ps->right_connections_num[srl_s]; int srl_s_under = st_look(&opt->srl_stack, 1); int srl_s_under_already_conns = opt->ps->right_connections_num[srl_s_under]; int top_is_usl = (sent->srl_right_degree[srl_s] == srl_s_already_conns); int under_top_is_usl = (sent->srl_right_degree[srl_s_under] == srl_s_under_already_conns); if (ap->is_srl_early_reduce || (!top_is_usl && !under_top_is_usl) ) { // srl_s_under will be active earlier than srl_s if (lexicograph_ignore_double_entries_comp( sent->srl_right_indices[srl_s_under] + srl_s_under_already_conns, sent->srl_right_degree[srl_s_under] - srl_s_under_already_conns, sent->srl_right_indices[srl_s] + srl_s_already_conns, sent->srl_right_degree[srl_s] - srl_s_already_conns) < 0) { opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt); //DEBUG //TMP printf("SRL_FLIP\n"); continue; } } else { // if a top word can be reduce from the top if (top_is_usl) { int first_usf = get_useful(&opt->srl_stack, 1, opt->ps->right_connections_num, sent->srl_right_degree); if (first_usf > 0) { // first 'useful' word in the stack should be attached to front of queue -- start remioving useless words // next words will be removed on the next rounds int next_connection = sent->srl_right_indices[first_usf][opt->ps->right_connections_num[first_usf]]; if (next_connection == opt->queue) { ASSERT(as.acts[SRL_RED]); opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); continue; //DEBUG //printf("SRL_RED, useless reduction\n"); } } } else { // if int second_usf = get_useful(&opt->srl_stack, 1, opt->ps->right_connections_num, sent->srl_right_degree); ASSERT(second_usf != srl_s_under); if (second_usf > 0) { int second_usf_already_conns = opt->ps->right_connections_num[second_usf]; if (lexicograph_ignore_double_entries_comp( sent->srl_right_indices[second_usf] + second_usf_already_conns, sent->srl_right_degree[second_usf] - second_usf_already_conns, sent->srl_right_indices[srl_s] + srl_s_already_conns, sent->srl_right_degree[srl_s] - srl_s_already_conns) < 0) { opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt); as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); ASSERT(as.acts[SRL_RED]); opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); // DEBUG printf("SRL_FLIP, followed by SRL_RED\n"); //printf("SRL_RED, preceded by SRL_FLIP\n"); continue; } } } // !top_is_usl } // !ap->is_synt_early_reduce } // FLIP //check SRL_SWITCH if (as.acts[SRL_SWITCH]) { int q = opt->queue; if (srl_left_part_complete(opt->ps, sent, q)) { opt = create_option(SYNT_STEP, 1, SRL_SWITCH, SRL_SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); //DEBUG //printf("SRL_SWITCH\n"); continue; } } //check SRL_RED if (!ap->is_srl_early_reduce && as.acts[SRL_RED]) { int srl_s = st_peek(&opt->srl_stack); if (srl_everything_complete(opt->ps, sent, srl_s)) { opt = _action_srl_red(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("SRL_RED\n"); continue; } } if (as.acts[PREDIC_NO]) { int q = opt->queue; if (sent->sense[q] < 0) { opt = create_option(SRL_STEP, 1, PREDIC_NO, PREDIC_NO, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); //DEBUG //printf("PREDIC_NO\n"); continue; } } if (as.acts[PREDIC_YES]) { int q = opt->queue; int q_sense = sent->sense[q]; if (q_sense >= 0) { int q_bank = sent->bank[q]; int q_lemma = sent->lemma[q]; //create sequence of predicate prediction operations opt = create_option(SRL_STEP, 0, opt->previous_act, PREDIC_YES, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sense[q_bank][q_lemma][0], mp->sense_num[q_bank][q_lemma]); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); set_links(ap, mp, opt, sent); opt = create_option(SRL_STEP, 1, PREDIC_YES, q_sense, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps)); ps_set_sense(opt->ps, q, q_sense); set_links(ap, mp, opt, sent); //DEBUG //printf("PREDIC_YES\n"); continue; } } if (as.acts[SRL_FLIP] && ap->intern_srl_deproj != DEPROJ_EXHAUSTIVE) { opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt); //DEBUG //printf("SRL_FLIP\n"); continue; } // if stalled in syntactic part if (IS_NOW_SYNTAX(opt->previous_act)) { //DEBUG printf("STALLED IN SYNTAX\n"); } else { //DEBUG printf("STALLED IN SRL\n"); } ASSERT(0); if (IS_NOW_SYNTAX(opt->previous_act)) { fprintf(stderr, "(Syntax) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); printf("(Syntax) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); } else { //TMP fprintf(stderr, "(SRL) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); //TMP printf("(SRL) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n"); } fprintf(stderr, "Try changing PARSING_ORDER in the configuration file to a larger value\n"); // printf("%s\n", print_sent(sent, 1)); //TODO this should be a fatal error fprintf(stderr, "Warning: returning partial derivation\n"); DEF_ALLOC(as_final, ACTION_SET); bzero(as_final, sizeof(ACTION_SET)); set_mask(mp, opt, as_final); free(as_final); TRY_FREE_PARTIALS(&(opt->pt), &(opt->ps)); return opt; //TODO restore! //exit(1); } //DEBUG //TMP printf("==== SENT FINISHED ===== \n"); if (!check_pt_t_equality(opt->pt, sent)) { fprintf(stderr, "Presumably: bug in parsing or in input file (e.g. NON-PROJECTIVITY): resulting syntactic trees do not match\n"); exit(1); } if (!check_ps_t_equality(opt->ps, sent)) { fprintf(stderr, "Presumably: bug in SRL parsing or in input file (e.g. NON-PROJECTIVITY): resulting predicate argument structures do not match\n"); } DEF_ALLOC(as, ACTION_SET); bzero(as, sizeof(ACTION_SET)); set_mask(mp, opt, as); free(as); TRY_FREE_PARTIALS(&(opt->pt), &(opt->ps)); return opt; }
//TODO don't forget to move pt OPTION_LIST *process_opt(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, OPTION **new_b_options, int *new_cand_num, OPTION *opt, OPTION_LIST *ol) { /* if ol longer than QUEUE_SIZE_LIMIT, then prune to half that length. Requires calling with opt=NULL to initialize count */ static int queue_size; if (opt == NULL) { queue_size = 0; OPTION_LIST *ol2; for (ol2 = ol; ol2 != NULL; ol2 = ol2->prev) queue_size++; return ol; } queue_size--; ASSERT(opt->outputs.num == ACTION_NUM); double min_lprob = - MAXDOUBLE; double min_lprob_with_pred = -MAXDOUBLE; if (*new_cand_num == ap->beam) { min_lprob = new_b_options[ap->beam - 1]->lprob - max_word_pred_lprob(ap, mp, sent, new_b_options, *new_cand_num, opt); min_lprob_with_pred = new_b_options[ap->beam - 1]->lprob; } //do not need to consider if (opt->lprob < min_lprob) { pt_free(&(opt->pt)); ps_free(&(opt->ps)); free_options(opt); return ol; } //they are not yet computed ACTION_SET as = get_next_actions(ap, mp, opt, sent); set_mask(mp, opt, &as); comp_option(ap, mp, opt); // ----------------------- SYNTAX ----------------------------------------------- //check SHIFT (first because it is the operation that updates candidate list) if (as.acts[SHIFT]) { if (log(opt->outputs.q[SHIFT]) + opt->lprob >= min_lprob) { //create sequence of shift operation //update queue and stack //TODO Implement more efficiently pruning after each decision OPTION *as_opt = create_option(SYNT_STEP, 0, opt->previous_act, SHIFT, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_pos, get_pos_out_num()); int pos = sent->pos[opt->period + ap->input_offset]; int feat = sent->feat_out[opt->period + ap->input_offset]; int word = sent->word_out[opt->period + ap->input_offset]; set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); if (log(as_opt->outputs.q[pos]) + as_opt->lprob < min_lprob_with_pred) { pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); free_option(as_opt); } else { OPTION *last_opt = create_word_prediction_seq(ap, mp, sent, as_opt, 1); OPTION *feat_opt = last_opt->previous_option->previous_option; comp_option(ap, mp, feat_opt); if (log(feat_opt->outputs.q[feat]) + feat_opt->lprob < min_lprob_with_pred) { pt_free(&(last_opt->pt)); ps_free(&(last_opt->ps)); OPTION *po = last_opt->previous_option, *ppo = last_opt->previous_option->previous_option; free_option(last_opt); free_option(po); free_option(ppo); free_option(as_opt); } else { OPTION *word_opt = last_opt->previous_option; comp_option(ap, mp, word_opt); // if (log(word_opt->outputs.q[word]) + word_opt->lprob < min_lprob_with_pred) { if (log(word_opt->outputs.q[word]) + word_opt->lprob < min_lprob_with_pred + SMALL_POS_VAL) { pt_free(&(last_opt->pt)); ps_free(&(last_opt->ps)); OPTION *po = last_opt->previous_option, *ppo = last_opt->previous_option->previous_option; free_option(last_opt); free_option(po); free_option(ppo); free_option(as_opt); } else { fill_lprob(last_opt); add_to_best_list(ap, new_b_options, new_cand_num, last_opt); } } } } } //update if (*new_cand_num == ap->beam) { min_lprob = new_b_options[ap->beam - 1]->lprob - max_word_pred_lprob(ap, mp, sent, new_b_options, *new_cand_num, opt); min_lprob_with_pred = new_b_options[ap->beam - 1]->lprob; // not necessary, but could save space: //ol = prune_options(ol, min_lprob); } //check LA if (as.acts[LA]) { int d = st_peek(&opt->stack); int h = opt->queue; if (log(opt->outputs.q[LA]) + opt->lprob >= min_lprob) { //create sequence of LA operations //update queue and stack OPTION *as_opt = create_option(SYNT_STEP, 0, opt->previous_act, LA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_la_label, mp->deprel_num); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double deprel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_DEPREL_SIZE]; int fanout = get_best_labels(ap, as_opt, deprel_min_prob, mp->deprel_num, best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SYNT_STEP, 1, LA, best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); pt_add_link(new_opt->pt, h, d, best_rels[i]); if (ap->intern_synt_deproj == DEPROJ_NO) { st_pop(&new_opt->stack); } else { // Do nothing } set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } //check RA if (as.acts[RA]) { int d = opt->queue; int h = st_peek(&opt->stack); //when agrees if (log(opt->outputs.q[RA]) + opt->lprob >= min_lprob) { //create sequence of RA operations //update queue and stack OPTION *as_opt = create_option(SYNT_STEP, 0, opt->previous_act, RA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_ra_label, mp->deprel_num); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double deprel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_DEPREL_SIZE]; int fanout = get_best_labels(ap, as_opt, deprel_min_prob, mp->deprel_num, best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SYNT_STEP, 1, RA, best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); pt_add_link(new_opt->pt, h, d, best_rels[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } //TODO Try processing immediately SHIFT operation //should speed-up (it will make it way to best_list and //prune other optinos) } } //check RED if (as.acts[RED]) { if (log(opt->outputs.q[RED]) + opt->lprob >= min_lprob) { //create sequence of reduce operation //update queue and stack OPTION *as_opt = create_option_light(SYNT_STEP, 1, RED, RED, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); st_pop(&as_opt->stack); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } //check SWITCH if (as.acts[SWITCH]) { if (log(opt->outputs.q[SWITCH]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SRL_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); // OPTION *as_opt = create_option_light(SYNT_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, // pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } // ----------------------- SEMANTICS ----------------------------------------------- //check PREDIC_NO if (as.acts[PREDIC_NO]) { if (log(opt->outputs.q[PREDIC_NO]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SRL_STEP, 1, PREDIC_NO, PREDIC_NO, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } if (as.acts[PREDIC_YES]) { int q = opt->queue; int q_bank = sent->bank[q]; int q_lemma = sent->lemma[q]; if (log(opt->outputs.q[PREDIC_YES]) + opt->lprob >= min_lprob) { //create sequence of predicate prediction operations OPTION *as_opt = create_option(SRL_STEP, 0, opt->previous_act, PREDIC_YES, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sense[q_bank][q_lemma][0], mp->sense_num[q_bank][q_lemma]); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double sense_min_prob = exp(min_lprob - as_opt->lprob); int best_senses[MAX_SENSE_SIZE]; int fanout = get_best_labels(ap, as_opt, sense_min_prob, mp->sense_num[q_bank][q_lemma], best_senses); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SRL_STEP, 1, PREDIC_YES, best_senses[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); ps_set_sense(new_opt->ps, q, best_senses[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } //check SRL_LA int q_bank = sent->bank[opt->queue]; if (q_bank >= 0 && as.acts[SRL_LA[q_bank]]) { int d = st_peek(&opt->srl_stack); int h = opt->queue; if (log(opt->outputs.q[SRL_LA[q_bank]]) + opt->lprob >= min_lprob) { //create sequence of SRL_LA operations //update queue and stack OPTION *as_opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_LA[q_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_la_label[q_bank], mp->role_num[q_bank]); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double rel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_ROLE_SIZE]; int fanout = get_best_labels(ap, as_opt, rel_min_prob, mp->role_num[q_bank], best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SRL_STEP, 1, SRL_LA[q_bank], best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); ps_add_link(new_opt->ps, h, d, best_rels[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } q_bank = -1; //check SRL_RA int s_bank = sent->bank[st_peek(&opt->srl_stack)]; if (s_bank >= 0 && as.acts[SRL_RA[s_bank]]) { int d = opt->queue; int h = st_peek(&opt->srl_stack); if (log(opt->outputs.q[SRL_RA[s_bank]]) + opt->lprob >= min_lprob) { //create sequence of RA operations //update queue and stack OPTION *as_opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_RA[s_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_sem_ra_label[s_bank], mp->role_num[s_bank]); set_links(ap, mp, as_opt, sent); comp_option(ap, mp, as_opt); double rel_min_prob = exp(min_lprob - as_opt->lprob); int best_rels[MAX_ROLE_SIZE]; int fanout = get_best_labels(ap, as_opt, rel_min_prob, mp->role_num[s_bank], best_rels); int i; for (i = 0; i < fanout; i++) { OPTION *new_opt = create_option_light(SRL_STEP, 1, SRL_RA[s_bank], best_rels[i], as_opt, as_opt->period, &as_opt->stack, &as_opt->srl_stack, as_opt->queue, pt_clone(as_opt->pt), ps_clone(as_opt->ps), &mp->out_link_act, ACTION_NUM); ps_add_link(new_opt->ps, h, d, best_rels[i]); set_links(ap, mp, new_opt, sent); fill_lprob(new_opt); ol = increase_list_asc(ol, new_opt); queue_size++; } pt_free(&(as_opt->pt)); ps_free(&(as_opt->ps)); as_opt->pt = NULL; as_opt->ps = NULL; if (fanout == 0) { free_option(as_opt); } } } s_bank = -1; //check SRL_RED if (as.acts[SRL_RED]) { if (log(opt->outputs.q[SRL_RED]) + opt->lprob >= min_lprob) { //create sequence of reduce operation //update queue and stack OPTION *as_opt = create_option_light(SRL_STEP, 1, SRL_RED, SRL_RED, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); st_pop(&as_opt->srl_stack); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } //check SRL_SWITCH if (as.acts[SRL_SWITCH]) { if (log(opt->outputs.q[SRL_SWITCH]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SYNT_STEP, 1, SRL_SWITCH, SRL_SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } if (as.acts[SRL_FLIP]) { if (log(opt->outputs.q[SRL_FLIP]) + opt->lprob >= min_lprob) { OPTION *as_opt = create_option_light(SRL_STEP, 1, SRL_FLIP, SRL_FLIP, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); int srl_s = st_pop(&as_opt->srl_stack); int srl_s_under = st_pop(&as_opt->srl_stack); st_push(&as_opt->srl_stack, srl_s); st_push(&as_opt->srl_stack, srl_s_under); set_links(ap, mp, as_opt, sent); fill_lprob(as_opt); ol = increase_list_asc(ol, as_opt); queue_size++; } } pt_free(&(opt->pt)); ps_free(&(opt->ps)); opt->pt = NULL; opt->ps = NULL; if (opt->next_options->prev == NULL) { free_options(opt); } if (queue_size > QUEUE_SIZE_LIMIT) { printf("Warning: indiscriminately pruning search queue from length %d to %d\n", queue_size, (int) (QUEUE_SIZE_LIMIT / 1.5)); OPTION_LIST *ol2; int cnt = 0; for (ol2 = ol; ol2 != NULL; ol2 = ol2->prev) { cnt++; if (cnt > (int) (QUEUE_SIZE_LIMIT / 1.5)) { // reduce to 2/3 of limit prune_options(ol2, 0.0); break; } } queue_size = cnt - 1; } return ol; }