示例#1
0
int main (int argc, char *argv[]) {
  if (argc == 1) {
    Stage st;
    st.input(std::cin);
    st.output(std::cout);
    Data res = solve(st);
    simulate(st, std::cout, res.records);
    std::cout << res.count << std::endl;
  }
  else if (strcmp(argv[1], "calc") == 0) {
    if (argc != 2) help();
    std::vector<std::string> problems;
    std::ifstream ifs("dat/LIST");
    std::string in;
    while (ifs >> in) problems.push_back(in);
    for (std::string i: problems) {
      std::ifstream ifs(("dat/" + i + ".dat").c_str());
      if (!ifs) std::cerr << "FILE NOT EXISTS -- " <<
                  "dat/" << i << ".dat" << std::endl;
      std::ofstream ofs(("asi1024/" + i).c_str());
      Stage st;
      st.input(ifs);
      Data res = solve(st);
      for (Record r: res.records) {
        ofs << r.y << " " << r.x << std::endl;
        st.swap(r.y, r.x);
      }
      std::cerr << i << "\t" << st.score <<
        "\t(Node: " << res.count << ")" << std::endl;
      st.clear();
    }
  }
  else if (strcmp(argv[1], "eval") == 0) {
示例#2
0
AbstractSlot * Stage::getSlot(const std::string & path)
{
    const auto names = cppassist::string::split(path, '.', true);

    Stage * stage = this;

    for (size_t i=0; i<names.size(); i++)
    {
        const std::string & name = names[i];

        // Ignore own stage name at the beginning
        if (name == stage->name() && i == 0)
        {
            continue;
        }

        // Check if stage is a pipeline and has a substage with the given name
        if (stage->isPipeline())
        {
            Pipeline * pipeline = static_cast<Pipeline *>(stage);
            Stage * sub = pipeline->stage(name);

            if (sub)
            {
                stage = sub;
                continue;
            }
        }

        // If there is no more substage but more names to fetch, return error
        if (i != names.size() - 1)
        {
            return nullptr;
        }

        // Check if stage has a slot with that name
        auto inputSlot = stage->input(name);
        if (inputSlot) {
            return inputSlot;
        }

        auto outputSlot = stage->output(name);
        if (outputSlot) {
            return outputSlot;
        }
    }

    return nullptr;
}