void Pgr_linear<G>::calculateVertices(G &graph) { debug << "Calculating vertices\n"; V_i vi; for (vi = vertices(graph.graph).first; vi != vertices(graph.graph).second; ++vi) { debug << "Checking vertex " << graph.graph[(*vi)].id << '\n'; if (is_linear(graph, *vi)) { linearVertices += (*vi); } } linearVertices -= forbiddenVertices; }
unsigned AudioStream::getEncoded(Encoded addr, unsigned frames) { unsigned count = 0, len; if(is_linear(info.encoding)) return getMono((Linear)addr, frames); while(frames--) { len = AudioFile::getBuffer(addr); // packet read if(len < info.framesize) break; addr += info.framesize; ++count; } return count; }
void glpk_wrapper::set_constraint(int index, Enode * const e) { DREAL_LOG_INFO << "glpk_wrapper::set_constraint " << e << " with " << e->getPolarity(); assert(is_linear(e)); changed = true; LAExpression la(e); auto vars = e->get_vars(); auto s = vars.size(); auto indices = new int[s + 1]; auto values = new double[s + 1]; int i = 1; for (auto it = la.begin(); it != la.end(); ++it) { auto v = it->first; double c = it->second; if (v != nullptr && c != 0.0) { DREAL_LOG_INFO << "glpk_wrapper::set_constraint " << c << " * " << v; indices[i] = get_index(v) + 1; values[i] = c; i += 1; } else { if (e->isEq()) { assert(!e->hasPolarity() || e->getPolarity() != l_False); DREAL_LOG_INFO << "glpk_wrapper::set_constraint == " << c; glp_set_row_bnds(lp, index, GLP_FX, -c, -c); } else { if (!e->hasPolarity() || e->getPolarity() != l_False) { DREAL_LOG_INFO << "glpk_wrapper::set_constraint <= " << (-c); glp_set_row_bnds(lp, index, GLP_UP, 0, -c); } else { DREAL_LOG_INFO << "glpk_wrapper::set_constraint >= " << (-c); glp_set_row_bnds(lp, index, GLP_LO, -c, 0); } } } } glp_set_mat_row(lp, index, i-1, indices, values); delete[] indices; delete[] values; // name the constraints (helps debugging) if (DREAL_LOG_INFO_IS_ON) { std::ostringstream stream; if (e->getPolarity() == l_False) { stream << "¬"; } stream << e; glp_set_row_name(lp, index, stream.str().c_str()); } }
unsigned AudioStream::putEncoded(Encoded addr, unsigned frames) { unsigned count = 0; ssize_t len; if(is_linear(info.encoding)) return putMono((Linear)addr, frames); while(frames--) { len = putBuffer(addr); if(len < (ssize_t)info.framesize) break; addr += info.framesize; ++count; } return count; }
void Audio::swapEncoded(Info &info, Encoded buffer, size_t bytes) { char buf; if(!is_linear(info.encoding)) return; if(!info.order || info.order == __BYTE_ORDER) return; // options for machine optimized should be inserted here bytes /= 2; while(bytes--) { buf = buffer[1]; buffer[1] = *buffer; *buffer = buf; buffer += 2; } }
void AudioStream::open(const char *fname, Mode m, timeout_t framing) { if(!framing) framing = 20; close(); AudioFile::open(fname, m, framing); if(!is_open()) return; streamable = true; if(is_linear(info.encoding)) return; codec = AudioCodec::get(info); if(!codec) streamable = false; else framebuf = new unsigned char[maxFramesize(info)]; }
void AudioStream::create(const char *fname, Info *info, bool exclusive, timeout_t framing) { if(!framing) framing = 20; close(); AudioFile::create(fname, info, exclusive, framing); if(!is_open()) return; streamable = true; if(is_linear(AudioFile::info.encoding)) return; codec = AudioCodec::get(AudioFile::info); if(!codec) { streamable = false; return; } framebuf = new unsigned char[maxFramesize(AudioFile::info)]; }
void MyWindow::perform_mink_sum() { if (red_set.number_of_polygons_with_holes() > 1 || blue_set.number_of_polygons_with_holes() > 1) { mink_sum_warning(); return; } Polygon_with_holes red_p_wh; CGAL::Oneset_iterator<Polygon_with_holes> oi1(red_p_wh); red_set.polygons_with_holes(oi1); if (red_p_wh.has_holes() || red_p_wh.is_unbounded()) { mink_sum_warning(); return; } const Polygon_2& red_p = red_p_wh.outer_boundary(); Polygon_with_holes blue_p_wh; CGAL::Oneset_iterator<Polygon_with_holes> oi2(blue_p_wh); blue_set.polygons_with_holes(oi2); if (blue_p_wh.has_holes() || blue_p_wh.is_unbounded()) { mink_sum_warning(); return; } QCursor old = widget->cursor(); widget->setCursor(Qt::WaitCursor); const Polygon_2& blue_p = blue_p_wh.outer_boundary(); if (is_linear(red_p) && is_linear(blue_p)) { const Linear_polygon_2& linear_red_p = circ_2_linear(red_p); const Linear_polygon_2& linear_blue_p = circ_2_linear(blue_p); const Linear_polygon_with_holes_2& res_p = CGAL::minkowski_sum_2(linear_red_p, linear_blue_p); Polygon_with_holes res_p_wh = linear_2_circ(res_p); res_set.clear(); res_set.insert(res_p_wh); newtoolbar->reset(); std::list<Polygon_with_holes> res_pgns; res_pgns.push_back(res_p_wh); draw_result(res_pgns.begin(), res_pgns.end()); widget->setCursor(old); } else if (is_disc(red_p) && is_linear(blue_p)) { const Linear_polygon_2& linear_blue_p = circ_2_linear(blue_p); const Polygon_with_holes& res_p_wh = CGAL::approximated_offset_2 (linear_blue_p, get_radius(red_p), 0.00001); res_set.clear(); res_set.insert(res_p_wh); newtoolbar->reset(); std::list<Polygon_with_holes> res_pgns; res_pgns.push_back(res_p_wh); draw_result(res_pgns.begin(), res_pgns.end()); widget->setCursor(old); } else if (is_disc(blue_p) && is_linear(red_p)) { const Linear_polygon_2& linear_red_p = circ_2_linear(red_p); const Polygon_with_holes& res_p_wh = CGAL::approximated_offset_2 (linear_red_p, get_radius(blue_p), 0.00001); res_set.clear(); res_set.insert(res_p_wh); newtoolbar->reset(); std::list<Polygon_with_holes> res_pgns; res_pgns.push_back(res_p_wh); draw_result(res_pgns.begin(), res_pgns.end()); widget->setCursor(old); } else { mink_sum_warning(); widget->setCursor(old); return; } }
void Pgr_linear<G>::doContraction(G &graph) { std::ostringstream contraction_debug; contraction_debug << "Performing contraction\n"; std::priority_queue<V, std::vector<V>, std::greater<V> > linearPriority; for (const auto linearVertex : linearVertices) { linearPriority.push(linearVertex); } contraction_debug << "Linear vertices" << std::endl; for (const auto v : linearVertices) { contraction_debug << graph[v].id << ", "; } contraction_debug << std::endl; while (!linearPriority.empty()) { V current_vertex = linearPriority.top(); linearPriority.pop(); if (!is_linear(graph, current_vertex)) { linearVertices -= current_vertex; continue; } Identifiers<V> adjacent_vertices = graph.find_adjacent_vertices(current_vertex); pgassert(adjacent_vertices.size() == 2); V vertex_1 = adjacent_vertices.front(); adjacent_vertices.pop_front(); V vertex_2 = adjacent_vertices.front(); adjacent_vertices.pop_front(); contraction_debug << "Adjacent vertices\n"; contraction_debug << graph[vertex_1].id << ", " << graph[vertex_2].id << std::endl; if (graph.m_gType == DIRECTED) { if (graph.out_degree_to_vertex(vertex_1, current_vertex) > 0 && graph.in_degree_from_vertex(vertex_2, current_vertex) > 0) { E e1 = graph.get_min_cost_edge(vertex_1, current_vertex); E e2 = graph.get_min_cost_edge(current_vertex, vertex_2); add_shortcut(graph, current_vertex, e1, e2); } if (graph.out_degree_to_vertex(vertex_2, current_vertex) > 0 && graph.in_degree_from_vertex(vertex_1, current_vertex) > 0) { E e1 = graph.get_min_cost_edge(vertex_2, current_vertex); E e2 = graph.get_min_cost_edge(current_vertex, vertex_1); add_shortcut(graph, current_vertex, e1, e2); } } else if (graph.m_gType == UNDIRECTED) { if (graph.out_degree_to_vertex(vertex_1, current_vertex) > 0 && graph.in_degree_from_vertex(vertex_2, current_vertex) > 0) { contraction_debug << "UNDIRECTED graph before contraction\n"; graph.print_graph(contraction_debug); E e1 = graph.get_min_cost_edge(vertex_1, current_vertex); E e2 = graph.get_min_cost_edge(current_vertex, vertex_2); add_shortcut(graph, current_vertex, e1, e2); } } graph.disconnect_vertex(current_vertex); linearVertices -= current_vertex; if (is_linear(graph, vertex_1) && !forbiddenVertices.has(vertex_1)) { linearPriority.push(vertex_1); linearVertices += vertex_1; } if (is_linear(graph, vertex_2) && !forbiddenVertices.has(vertex_2)) { linearPriority.push(vertex_2); linearVertices += vertex_2; } } debug << contraction_debug.str().c_str() << "\n"; }
bool glpk_wrapper::is_simple_bound(Enode * const e) { Enode const * seen = nullptr; return is_linear(e) && only_one_var(e, &seen); }