当前位置: 首页>>代码示例>>C++>>正文


C++ PackedVector类代码示例

本文整理汇总了C++中PackedVector的典型用法代码示例。如果您正苦于以下问题:C++ PackedVector类的具体用法?C++ PackedVector怎么用?C++ PackedVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PackedVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: graph_t

InteractionGraph::InteractionGraph(MILPP* problem)
    : graph_t(problem->get_num_cols())
{
    int ri; /* row index */
    int ci; /* col index */
    int ni; /* neighbor index */
    PackedVector* row;

    problem_ = problem;

    /* Start forming variable neighbourhoods by using constraints */
    for (ri = 0; ri < problem->get_num_rows(); ri++)
    {
        row = problem->get_row(ri);
        for (ci = 0; ci < row->get_num_elements(); ci++)
            for (ni = 0; ni < row->get_num_elements(); ni++)
            {
                if ((ci == ni) || /* Skip variables with the same index */
                        edge(row->get_index_by_pos(ci),
                             row->get_index_by_pos(ni), *this).second)
                    continue;
                /* Add variable with index n as a neighbor for a
                   variable with index c*/
                add_edge(row->get_index_by_pos(ci),
                         row->get_index_by_pos(ni), *this);
            }
    }
}
开发者ID:darabbt,项目名称:les,代码行数:28,代码来源:interaction_graph.cpp

示例2: size_t

inline void PackedDeque::append_front(const uint64_t& value) {
    if (filled == vec.size()) {
        size_t new_capacity = size_t(factor * vec.size()) + 1;
        PackedVector new_vec;
        new_vec.resize(new_capacity);
        
        new_vec.set(0, value);
        for (size_t i = 0; i < filled; i++) {
            new_vec.set(i + 1, get(i));
        }
        
        vec = std::move(new_vec);
        begin_idx = 0;
    }
    else {
        if (begin_idx == 0) {
            begin_idx = vec.size() - 1;
        }
        else {
            begin_idx--;
        }
        vec.set(begin_idx, value);
    }
    
    filled++;
}
开发者ID:glennhickey,项目名称:vg,代码行数:26,代码来源:packed_structs.hpp

示例3: TEST_F

TEST_F(FidoVectorTest, makeSparse){
  EXPECT_EQ(3,pv.size());
  EXPECT_EQ(3,pv.numberEntries());
  PackedVector sparse = pv.makeSparse();
  EXPECT_EQ(6,sparse.size());
  EXPECT_EQ(6,sparse.numberEntries());
}
开发者ID:AndSi,项目名称:percolator,代码行数:7,代码来源:UnitTest_Percolator_Fido.cpp

示例4: get_row

void
MILPP::set_cons_matrix(const PackedMatrix* matrix)
{
  cons_matrix_ = *matrix;

  for (int i = 0; i < get_num_rows(); i++)
    {
      PackedVector* row = get_row(i);
      for (int j = 0; j < row->get_num_elements(); j++)
        {
          col_to_row_mapping_[ row->get_index_by_pos(j) ]->insert(i);
          row_to_col_mapping_[i]->insert( row->get_index_by_pos(j) );
        }
    }
}
开发者ID:darabbt,项目名称:les,代码行数:15,代码来源:milp_problem.cpp

示例5: contract

inline void PackedDeque::contract() {
    size_t shrink_capacity = vec.size() / (factor * factor);
    if (filled <= shrink_capacity) {
        PackedVector new_vec;
        new_vec.resize(filled);
        for (size_t i = 0; i < filled; i++) {
            new_vec.set(i, get(i));
        }
        
        vec = std::move(new_vec);
        begin_idx = 0;
    }
}
开发者ID:glennhickey,项目名称:vg,代码行数:13,代码来源:packed_structs.hpp

示例6: printf

void
MILPP::print()
{
  int i;
  int j;
  int offset;

  /* Print objective function sense and its coefficients */
  for (int i = 0; i < get_num_cols(); ++i)
    {
      if (i) printf(" + ");
      printf("%.1fx%d", get_obj_coef(i), i);
    }
  printf(" -> %s\n", obj_sense_to_string());
  /* Print constraints represented by rows */
  printf("subject to\n");
  for (i = 0; i < cons_matrix_.get_num_rows(); i++)
    {
      int t = 0; /* start from col zero */
      PackedVector* row = cons_matrix_.get_vector(i);
      printf("(%d) ", i);
      for (j = 0; j < row->get_num_elements(); j++)
        {
          if (j > 0)
            printf(" + ");
          //printf("[%d|%d]", row->get_index_by_pos(j), t);
          if ((offset = row->get_index_by_pos(j) - t) >= 1)
            {
              if (j > 0)
                offset -= 1;
              //printf("(%d)", offset);
              offset *= 5 + 3;
              for (int s = 0; s < offset; s++)
                printf(" ");
            }
          t = row->get_index_by_pos(j);

          printf("%.1fx%d", row->get_element_by_pos(j),
                 row->get_index_by_pos(j));
        }
      /* Print row sense */
      printf(" <= ");
      /* Print row upper bound */
      printf("%.1f", get_row_upper_bound(i));
      printf("\n");
    }

}
开发者ID:darabbt,项目名称:les,代码行数:48,代码来源:milp_problem.cpp

示例7: set

inline void PagedVector::set(const size_t& i, const uint64_t& value) {
    assert(i < filled);
    uint64_t anchor = anchors.get(i / page_size);
    if (anchor == 0) {
        // this page does not have a non-zero anchor yet, use this one
        anchors.set(i / page_size, value);
        anchor = value;
    }
    pages[i / page_size].set(i % page_size, to_diff(value, anchor));
}
开发者ID:glennhickey,项目名称:vg,代码行数:10,代码来源:packed_structs.hpp

示例8: append_back

inline void PackedDeque::append_back(const uint64_t& value) {
    // expand capacity if necessary
    if (filled == vec.size()) {
        size_t new_capacity = size_t(factor * vec.size()) + 1;
        reserve(new_capacity);
    }
    
    // update the pointer to the back
    filled++;
    
    // set the value
    vec.set(internal_index(filled - 1), value);
}
开发者ID:vgteam,项目名称:vg,代码行数:13,代码来源:packed_structs.hpp

示例9: pop

inline void PagedVector::pop() {
    filled--;
    while (filled + page_size <= pages.size() * page_size) {
        // the final page is unused now, remove it
        pages.pop_back(); // TODO: this won't resize since it's an STL vector
        anchors.pop();
    }
}
开发者ID:vgteam,项目名称:vg,代码行数:8,代码来源:packed_structs.hpp

示例10: pop_front

inline void PackedDeque::pop_front() {
    begin_idx++;
    if (begin_idx == vec.size()) {
        begin_idx = 0;
    }
    filled--;
    contract();
}
开发者ID:glennhickey,项目名称:vg,代码行数:8,代码来源:packed_structs.hpp

示例11: pop

inline void PagedVector::pop() {
    filled--;
    if (filled % page_size == 0) {
        // we've emptied a page, remove it
        pages.pop_back();
        anchors.pop();
    }
}
开发者ID:glennhickey,项目名称:vg,代码行数:8,代码来源:packed_structs.hpp

示例12: reserve

inline void PagedVector::reserve(const size_t& future_size) {
    if (future_size > pages.size() * page_size) {
        // how many pages does this require?
        size_t num_pages = (future_size - 1) / page_size + 1;
        // note: we don't need to worry about underflow b/c previous condition
        // implies future_size > 0
        
        // expand anchor and pages vectors out to the capacity of the number of pages
        anchors.reserve(num_pages);
        pages.reserve(num_pages);
        
        // add the anchors and fixed-width pages in this
        anchors.resize(num_pages);
        while (num_pages > pages.size()) {
            pages.emplace_back();
            pages.back().resize(page_size);
        }
    }
}
开发者ID:vgteam,项目名称:vg,代码行数:19,代码来源:packed_structs.hpp

示例13: append_front

inline void PackedDeque::append_front(const uint64_t& value) {
    // expand capacity if necessary
    if (filled == vec.size()) {
        size_t new_capacity = size_t(factor * vec.size()) + 1;
        reserve(new_capacity);
    }
    
    // update the pointer to the front
    if (begin_idx == 0) {
        begin_idx = vec.size() - 1;
    }
    else {
        begin_idx--;
    }
    // update the pointer to the back
    filled++;
    
    // set the value
    vec.set(internal_index(0), value);
}
开发者ID:vgteam,项目名称:vg,代码行数:20,代码来源:packed_structs.hpp

示例14: pop_front

inline void PackedDeque::pop_front() {
    // update the pointer to the beginning
    begin_idx++;
    if (begin_idx == vec.size()) {
        begin_idx = 0;
    }
    // update the pointer to the end
    filled--;
    
    // shrink if necessary
    contract();
}
开发者ID:vgteam,项目名称:vg,代码行数:12,代码来源:packed_structs.hpp

示例15: append

inline void PagedVector::append(const uint64_t& value) {
    if (filled % page_size == 0) {
        // init a new page and a new anchor
        pages.emplace_back();
        pages.back().resize(page_size);
        anchors.append(0);
    }
    
    // use the logic in set to choose anchor and diff
    filled++;
    set(filled - 1, value);
}
开发者ID:glennhickey,项目名称:vg,代码行数:12,代码来源:packed_structs.hpp


注:本文中的PackedVector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。