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


C++ vec::assign方法代码示例

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


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

示例1: gen

void gen(int kk, mat &a, vec &b)
{
        const int m = kk+2;
        b.assign(m, 1<<kk);
        a.assign(m,vec(m,0));
        a[0][0] = a[0][1] = 1;
        for (int i = 1; i < m; i++) {
                int kkk = kk-i+1;
                for (int j = 0; j <= kkk; j++) a[i][j+1] = c[kkk][j];
        }
}
开发者ID:hadrori,项目名称:hadrori.github.io,代码行数:11,代码来源:leo.cpp

示例2: assign

 void assign(indtype Nitem, indtype cap,
             indtype minCost_1, indtype *w, valtype *v)
 {
   this->Nitem = Nitem;
   cap = std::accumulate(w, w + Nitem, 0) - cap;
   this->cap = cap;
   INT nrow = cap + 1 - minCost_1, ncol = Nitem + 1;
   content.assign(nrow * ncol + ncol, -std::numeric_limits<valtype>::max());
   dp01kp<valtype, indtype, false>::assign(minCost_1, w, (valtype**)(&content[0]), v, 0);
   valtype *val = &content[ncol];
   for(INT i = 0; i < ncol; ++i)
   {
     dp01kp<valtype, indtype, false>::value[i] = val + nrow * i;
   }
 }
开发者ID:cran,项目名称:FLSSS,代码行数:15,代码来源:DPgapMultithreadKPs.cpp

示例3: gapBabDp

valtype gapBabDp(vec<signed char> &currentSolution, vec<signed char> &Bcontainer,
              indtype Nagent, indtype Ntask, WV<valtype, indtype> **info,
              indtype *residualBudget, int maxCore, std::time_t timer, double tlimit,
              int &Nnode, int &Nkp)
{
  vec<signed char*> Bv(Ntask);
  for(indtype j = 0; j < Ntask; ++j)
  {
    INT tmp = j * (INT(Nagent) + 1);
    Bv[j] = &Bcontainer[0] + tmp;
    Bv[j][Nagent] = 0;
  }
  signed char **B = &Bv[0];


  vec<indtype> overloadedAgent(Nagent);
  vec<vec<indtype> > overloadedAgentTask(Nagent, vec<indtype>(Ntask));
  vec<vec<indtype> > overloadedAgentWeight(Nagent, vec<indtype>(Ntask));
  vec<vec<valtype> > overloadedAgentPenalty(Nagent, vec<valtype>(Ntask)); // will be used as values in knapsacking
  vec<vec<indtype> > nextAgent(Nagent, vec<indtype>(Ntask));
  vec<vec<indtype> > reassign(Nagent, vec<indtype>(Ntask));
  vec<vec<indtype> > stay(Nagent, vec<indtype>(Ntask));


  vec<indtype> budgetExceedance(Nagent);
  vec<stackEle<valtype, indtype> > T(INT(Nagent) * Ntask);
  T.resize(0);
  currentSolution.resize(INT(Nagent) * Ntask);
  valtype currentSolutionRevenue = -std::numeric_limits<valtype>::max();


  // Auxiliary containers.
  maxCore = std::min<int> (maxCore, Nagent);
  vec<indtype> agentCosts(Nagent);


  // bool postKnapsack = false;
  while(true)
  {
    std::time_t now; std::time(&now);
    if(std::difftime(now, timer) > tlimit) break;


    while(true) // Repeat backtracking until knapsacking becomes necessary.
    {
      valtype revenueUB = 0;
      bool needNoBacktrack = findOverloadedAgentsPenaltyWeightNextAgent(
        revenueUB, overloadedAgent, info, B,
        Nagent, Ntask, residualBudget, &budgetExceedance[0], &agentCosts[0],
        overloadedAgentTask, overloadedAgentWeight, // of size Nagent
        overloadedAgentPenalty, // will be used as values in knapsacking
        nextAgent, T);
      // Rcout << "needNoBacktrack = " << needNoBacktrack << "\n";
      if(needNoBacktrack and revenueUB > currentSolutionRevenue)
      {
        if(overloadedAgent.size() > 0) break;
        currentSolution.assign(Bcontainer.begin(), Bcontainer.end());
        currentSolutionRevenue = revenueUB;
      }
      /*
      Rcout << "revenueUB = " << revenueUB << "\n";
      Rcout << "before backtrack, T.size() = " << T.size() << "\n";
      for(indtype i = 1, iend = T.size(); i < iend; ++i)
      {
        Rcout << T[i].agent << ", " << T[i].task << ", " <<
          int(B[T[i].task][T[i].agent]) << ",    ";
      }
      Rcout << "\n";
      for(indtype i = 0; i < Nagent; ++i)
      {
        for(indtype j = 0; j < Ntask; ++j)
        {
          if(B[j][i] >= 0) Rcout << " " << int(B[j][i]) << ", ";
          else Rcout << int(B[j][i]) << ", ";
        }
        Rcout << "\n";
      }
      */


      bool bt = backtrack(T, B, Nagent, info, residualBudget);
      /*
      Rcout << "after backtrack, T.size() = " << T.size() << "\n";
      for(indtype i = 1, iend = T.size(); i < iend; ++i)
      {
        Rcout << T[i].agent << ", " << T[i].task << ", " <<
          int(B[T[i].task][T[i].agent]) << ",    ";
      }
      Rcout << "\n";
      for(indtype i = 0; i < Nagent; ++i)
      {
        for(indtype j = 0; j < Ntask; ++j)
        {
          if(B[j][i] >= 0) Rcout << " " << int(B[j][i]) << ", ";
          else Rcout << int(B[j][i]) << ", ";
        }
        Rcout << "\n";
      }
      */
      if(!bt) return currentSolutionRevenue;
//.........这里部分代码省略.........
开发者ID:cran,项目名称:FLSSS,代码行数:101,代码来源:DPgapMultithreadKPs.cpp


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