Beispiel #1
0
    Gtk::Grid *SmartChessWindow::createSuboptionsArea() {
        const int SUBOPTIONS_ROWS = 3;
        const int SUBOPTIONS_COLS = 3;
        const int MARGIN = 1;

        mSubOptionsGrid = Gtk::manage(new Gtk::Grid());
        mSubOptionsGrid->set_vexpand();
        mSubOptionsGrid->set_hexpand(false);
        mSubOptionsGrid->set_column_homogeneous(true);
        mSubOptionsGrid->insert_column(0);

        for(auto i : IntRange(SUBOPTIONS_COLS))
            mSubOptionsGrid->insert_column(i);

        for(auto i : IntRange(SUBOPTIONS_ROWS))
            mSubOptionsGrid->insert_row(i);

        Gtk::Label* p1 = Gtk::manage(new Gtk::Label("Player 1"));
        p1->set_margin_left(MARGIN);
        p1->set_margin_right(MARGIN);
        mSubOptionsGrid->attach(*p1, 0, 0, 1, 1);

        Gtk::Label* vs = Gtk::manage(new Gtk::Label("V.S."));
        vs->set_margin_left(MARGIN);
        vs->set_margin_right(MARGIN);
        mSubOptionsGrid->attach(*vs, 1, 0, 1, 1);

        Gtk::Label* p2 = Gtk::manage(new Gtk::Label("Player 2"));
        p2->set_margin_left(MARGIN);
        p2->set_margin_right(MARGIN);
        mSubOptionsGrid->attach(*p2, 2, 0, 1, 1);

        mCbt1 = Gtk::manage(new Gtk::ComboBoxText());
        mCbt1->append("Human");
        mCbt1->append("A.I.");
        mCbt1->set_active(0);
        mSubOptionsGrid->attach(*mCbt1, 0, 1, 1, 1);

        mCbt2 = Gtk::manage(new Gtk::ComboBoxText());
        mCbt2->append("Human");
        mCbt2->append("A.I.");
        mCbt2->set_active(1);
        mSubOptionsGrid->attach(*mCbt2, 2, 1, 1, 1);

        rcg1 = Gtk::manage(new GRadioColorGroup());
        mSubOptionsGrid->attach(*rcg1, 0, 2, 1, 1);

        rcg2 = Gtk::manage(new GRadioColorGroup());
        mSubOptionsGrid->attach(*rcg2, 2, 2, 1, 1);

        rcg1->signalClickedWhite().connect(sigc::mem_fun(rcg2, &GRadioColorGroup::setBlack));
        rcg1->signalClickedBlack().connect(sigc::mem_fun(rcg2, &GRadioColorGroup::setWhite));
        rcg2->signalClickedWhite().connect(sigc::mem_fun(rcg1, &GRadioColorGroup::setBlack));
        rcg2->signalClickedBlack().connect(sigc::mem_fun(rcg1, &GRadioColorGroup::setWhite));
        rcg1->setWhite();
        rcg2->setBlack();
        return mSubOptionsGrid;
    }
Beispiel #2
0
    Gtk::Grid * SmartChessWindow::createMainGrid() const {
        Gtk::Grid* grid = Gtk::manage(new Gtk::Grid());
        grid->set_row_homogeneous(false);
        grid->set_column_homogeneous(false);
        grid->set_vexpand();
        grid->set_hexpand();

        for(auto i : IntRange(ROW_COUNT))
            grid->insert_row(i);

        for(auto i : IntRange(COLUMN_COUNT))
            grid->insert_column(i);

        return grid;
    }
Beispiel #3
0
    Gtk::Grid * SmartChessWindow::createOptionsArea() {
        const int OPTIONS_ROWS = 4;
        Gtk::Grid* options = Gtk::manage(new Gtk::Grid());
        options->set_vexpand();
        options->set_hexpand(false);
        options->insert_column(0);

        for(auto i : IntRange(OPTIONS_ROWS))
            options->insert_row(i);

        Gtk::Button* b = Gtk::manage(new Gtk::Button("Start"));
        b->set_hexpand(false);
        b->signal_clicked().connect(sigc::mem_fun(this, &SmartChessWindow::onStartGame));
        options->attach(*b, 0, 0, 1, 1);

        b = Gtk::manage(new Gtk::Button("End"));
        b->set_hexpand(false);
        b->signal_clicked().connect(sigc::mem_fun(this, &SmartChessWindow::onEndGame));
        options->attach(*b, 0, 1, 1, 1);

        b = Gtk::manage(new Gtk::Button("Reset"));
        b->set_hexpand(false);
        b->signal_clicked().connect(sigc::mem_fun(this, &SmartChessWindow::onResetGame));
        options->attach(*b, 0, 2, 1, 1);

        auto suboptions = createSuboptionsArea();
        options->attach(*suboptions, 0, 3, 1, 1);

        return options;
    }
DragValueCtrl* grid_text(wxWindow* parent,
  wxSizer* sizer,
  winvec_t& showhide,
  const Art& art,
  StatusInterface& statusInfo,
  const DialogFunc& showDialog)
{
  // Create the drag-adjustable grid spacing text

  auto text = make_wx<DragValueCtrl>(parent,
    IntRange(min_t(1)),
    Description(
     "Grid: Drag to adjust spacing. "
     "Right-Click to disable. "
     "Double-click for dialog"),
    DragCursor(art.Get(Cursor::DRAG_SCALE)),
    HoverCursor(art.Get(Cursor::MOVE_POINT)),
    statusInfo);
  showhide.push_back(text);
  text->Hide();

  events::on_mouse_left_double_click(text,
    [=](const IntPoint&){
      showDialog();
    });

  sizer->Add(text, 0, wxALIGN_CENTER_VERTICAL);
  return text;
}
void
load_union(const Subset &s0, const Subset &s1,
           AssignmentContainer *nd0, AssignmentContainer *nd1,
           const EdgeData &ed, double max_error,
           ParticleStatesTable* pst,
           const statistics::Metrics &metrics,
           unsigned int max,
           AssignmentContainer *out) {
  Ints ii0= get_index(s0, ed.intersection_subset);
  Ints ii1= get_index(s1, ed.intersection_subset);
  Ints ui0= get_index(ed.union_subset, s0);
  Ints ui1= get_index(ed.union_subset, s1);
  Ints uii= get_index(ed.union_subset, ed.intersection_subset);
  Assignments nd1a
    = nd1->get_assignments(IntRange(0, nd1->get_number_of_assignments()));
  // chunck outer and writing later
  unsigned int nd0sz= nd0->get_number_of_assignments();
  for (unsigned int i=0; i< nd0sz; ++i) {
    Assignment nd0a=nd0->get_assignment(i);
    Assignment nd0ae=get_sub_assignment(nd0a, ii0);
    for (unsigned int j=0; j< nd1a.size(); ++j) {
      Assignment nd1ae=get_sub_assignment(nd1a[j], ii1);
      bool merged_ok=(nd1ae==nd0ae);
      Assignment ss;
      if (!merged_ok && pst) {;
        double n= get_distance_if_smaller_than(ed.intersection_subset,
                                               nd0ae, nd1ae, pst,
                                               metrics, max_error);
        if ( n < max_error) {
          merged_ok=true;
        }
      }
      if (merged_ok) {
        ss= get_merged_assignment(ed.union_subset,
                                  nd0a, ui0,
                                  nd1a[j], ui1);
      }
      if (merged_ok) {
        bool ok=true;
        for (unsigned int k=0; k< ed.filters.size(); ++k) {
          if (ed.filters[k]->get_is_ok(ss)) {
            // pass
          } else {
            ok=false;
            break;
          }
        }
        if (ok) {
          out->add_assignment(ss);
          if (out->get_number_of_assignments() > max) {
            IMP_WARN("Truncated number of states at " << max
                     << " when merging " << s0 << " and " << s1);
            return;
          }
        }
      }
    }
  }
}
Beispiel #6
0
// }
IntRanges ProbabilisticAnchorGraph::get_edge_list() const {
  IntRanges edge_list;
  GTraits::edge_iterator e, e_end;
  for (boost::tie(e, e_end) = boost::edges(g_); e != e_end; ++e) {
    edge_list.push_back(IntRange(boost::source(*e, g_), boost::target(*e, g_)));
  }
  return edge_list;
}
Assignments BranchAndBoundSampler::do_get_sample_assignments(const Subset &s)
    const {
  SubsetFilterTables sfts = DiscreteSampler::get_subset_filter_tables_to_use(
      get_restraints(), get_particle_states_table());
  IMP::PointerMember<AssignmentsTable> sst =
      DiscreteSampler::get_assignments_table_to_use(sfts);
  IMP_NEW(PackedAssignmentContainer, pac, ());
  sst->load_assignments(s, pac);
  return pac->get_assignments(IntRange(0, pac->get_number_of_assignments()));
}
Hierarchy create_protein(Model *m, std::string name, double resolution,
                         const Ints db) {
  Hierarchy root = Hierarchy::setup_particle(new Particle(m));
  Domain::setup_particle(root, IntRange(db.front(), db.back()));
  for (unsigned int i = 1; i < db.size(); ++i) {
    std::ostringstream oss;
    oss << name << "-" << i - 1;
    Hierarchy cur = create_protein(
        m, oss.str(), resolution, db[i] - db[i - 1], db[i - 1],
        atom::get_volume_from_mass(
            atom::get_mass_from_number_of_residues(db[i] - db[i - 1])),
        false);
    root.add_child(cur);
  }
  Molecule::setup_particle(root);
  root->set_name(name);
  return root;
}
Beispiel #9
0
void load_union(const Subset &s0, const Subset &s1, AssignmentContainer *nd0,
                AssignmentContainer *nd1, const EdgeData &ed, size_t max,
                AssignmentContainer *out) {
  Ints ii0 = get_index(s0, ed.intersection_subset);
  Ints ii1 = get_index(s1, ed.intersection_subset);
  Ints ui0 = get_index(ed.union_subset, s0);
  Ints ui1 = get_index(ed.union_subset, s1);
  Ints uii = get_index(ed.union_subset, ed.intersection_subset);
  Assignments nd1a =
      nd1->get_assignments(IntRange(0, nd1->get_number_of_assignments()));
  // chunck outer and writing later
  unsigned int nd0sz = nd0->get_number_of_assignments();
  IMP_PROGRESS_DISPLAY("Merging subsets " << s0 << " and " << s1,
                       nd0sz * nd1a.size());
  for (unsigned int i = 0; i < nd0sz; ++i) {
    Assignment nd0a = nd0->get_assignment(i);
    Assignment nd0ae = get_sub_assignment(nd0a, ii0);
    for (unsigned int j = 0; j < nd1a.size(); ++j) {
      Assignment nd1ae = get_sub_assignment(nd1a[j], ii1);
      if (nd1ae == nd0ae) {
        Assignment ss =
            get_merged_assignment(ed.union_subset, nd0a, ui0, nd1a[j], ui1);
        bool ok = true;
        for (unsigned int k = 0; k < ed.filters.size(); ++k) {
          if (!ed.filters[k]->get_is_ok(ss)) {
            ok = false;
            break;
          }
        }
        if (ok) {
          out->add_assignment(ss);
          if (out->get_number_of_assignments() > max) {
            IMP_WARN("Truncated number of states at " << max << " when merging "
                                                      << s0 << " and " << s1);
            return;
          }
        }
      }
      IMP::base::add_to_progress_display(1);
    }
  }
}
Beispiel #10
0
InferenceStatistics::Data InferenceStatistics::get_data(
    const Subset &, AssignmentContainer *iss) const {
  Assignments ss =
      iss->get_assignments(IntRange(0, iss->get_number_of_assignments()));
  Data ret;
  ret.size = iss->get_number_of_assignments();
  Ints sample;
  for (int i = 0; i < ret.size; ++i) {
    if (sample.size() < sample_size) {
      sample.push_back(i);
    } else {
      double prob = static_cast<double>(sample_size) / i;
      if (select_(base::random_number_generator) < prob) {
        int replace = place_(base::random_number_generator);
        sample[replace] = i;
      }
    }
  }
  ret.sample.resize(sample.size());
  for (unsigned int i = 0; i < sample.size(); ++i) {
    ret.sample[i] = iss->get_assignment(sample[i]);
  }
  return ret;
}
Beispiel #11
0
IntRange _test_intrange() { return IntRange(-1, -1); }
Beispiel #12
0
 IntRange GetFacetDofs (int nr) const
 { 
   return IntRange (first_facet_dof[nr], first_facet_dof[nr+1]); 
 }
Beispiel #13
0
IntRange range(int min, int max) {
    return IntRange(min, max);
}
Beispiel #14
0
 ElementRange Elements (VorB vb = VOL) const
 {
   return ElementRange (*this, vb, IntRange (0, ma->GetNE(vb)));
 }
Beispiel #15
0
IntRange range(int length) {
    return IntRange(length);
}
Beispiel #16
0
  void MyVTKOutput<D>::Do(LocalHeap & lh, const BitArray * drawelems)
  {
    ostringstream filenamefinal;
    filenamefinal << filename << output_cnt << ".vtk";
    ofstream fileout(filenamefinal.str());
    cout << " Writing VTK-Output";
    if (output_cnt > 0)
      cout << " ( " << output_cnt << " )";
    cout << ":" << flush;

    output_cnt++;

    if (nocache)
      BuildGridString();

    fileout << grid_str;

    int ne = ma->GetNE();

    IntRange range = only_element >= 0 ? IntRange(only_element,only_element+1) : IntRange(ne);

    for (int elnr : range)
    {
      if (drawelems && !(drawelems->Test(elnr)))
          continue;

      HeapReset hr(lh);

      ElementTransformation & eltrans = ma->GetTrafo(elnr, VOL, lh);
      auto el = ma->GetElement(elnr);
      ELEMENT_TYPE et = el.GetType();
      if (et == ET_TRIG || et == ET_TET)
      {
        for (auto ip : ref_vertices)
        {
          MappedIntegrationPoint<D,D> mip(ip, eltrans);
          for (int i = 0; i < coefs.Size(); i++)
          {
            const int dim = coefs[i]->Dimension();
            FlatVector<> tmp(dim,lh);
            coefs[i]->Evaluate(mip,tmp);
            for (int d = 0; d < dim; ++d)
              value_field[i]->Append(tmp(d));
          }
        }
      }
      else
      {
        const POINT3D *vertices = ElementTopology::GetVertices(et);
        int nv = ElementTopology::GetNVertices(et);

        for (int j = 0; j < nv; ++j)
        {
          MappedIntegrationPoint<D,D> mip(IntegrationPoint(vertices[j][0], vertices[j][1], vertices[j][2]), eltrans);
          for (int i = 0; i < coefs.Size(); ++i)
          {
            const int dim = coefs[i]->Dimension();
            FlatVector<> tmp(dim,lh);
            coefs[i]->Evaluate(mip,tmp);
            for (int d = 0; d < dim; ++d)
              value_field[i]->Append(tmp(d));
          }
        }
      }

    }

    PrintFieldData(fileout);

    for (auto field : value_field)
      field->SetSize(0);

    cout << " Done." << endl;
  }
Beispiel #17
0
  void MyVTKOutput<D>::BuildGridString()
  {
    ostringstream ss;
    // header:
    ss << "# vtk DataFile Version 3.0" << endl;
    ss << "vtk output" << endl;
    ss << "ASCII" << endl;
    ss << "DATASET UNSTRUCTURED_GRID" << endl;

    int ne = ma->GetNE();

    IntRange range = only_element >= 0 ? IntRange(only_element,only_element+1) : IntRange(ne);

    Array<Vec<D>> points;
    Array<Array<int>> cells;
    Array<int> cell_types;
    int pointcnt = 0;
    LocalHeap lh(1000000);
    bool maybewarn = subdivision != 0;
    for (int elnr : range)
    {
      HeapReset hr(lh);

      auto el = ma->GetElement(elnr);
      auto et = el.GetType();
      if (et == ET_TRIG || et == ET_TET)
      {
        ElementTransformation & eltrans = ma->GetTrafo(elnr, VOL, lh);

        int offset = points.Size();
        for (auto ip : ref_vertices)
        {
          MappedIntegrationPoint<D,D> mip(ip, eltrans);
          points.Append(mip.GetPoint());
        }

        for (auto tet : ref_elements)
        {
          Array<int> new_tet;
          for (int i = 0; i < D+1; ++i)
          {
            pointcnt++;
            new_tet.Append(tet[i] + offset);
          }
          cells.Append(new_tet);
          cell_types.Append(ElementTypeToVTKType(et));
        }
      }
      else
      {
        if (maybewarn)
        {
          cout << endl << " Warning: VTKOutput: subdivision not implemented for element types other than trigs / tets" << endl;
          maybewarn = false;
        }
        auto vertices = el.Vertices();

        Array<int> element_point_ids;
        for (int p : vertices)
        {
          points.Append(ma->GetPoint<D>(p));
          element_point_ids.Append(points.Size() - 1);
          pointcnt++;
        }

        cells.Append(element_point_ids);
        cell_types.Append(ElementTypeToVTKType(et));
      }
    }

    ss << "POINTS " << points.Size() << " float" << endl;
    for (const Vec<D> & p : points)
    {
      int i = 0;
      for (; i < D; ++i)
        ss << p[i] << " ";

      for (; i < 3; ++i)
        ss << "\t 0.0";
      ss << endl;
    }

    ss << "CELLS " << cells.Size() << " " << pointcnt + cells.Size() << endl;
    for (const Array<int> & c : cells)
    {
      ss << c.Size() << " ";
      for (int point : c)
        ss << point << " ";
      ss << endl;
    }

    ss << "CELL_TYPES " << cell_types.Size() << endl;
    for (int ct : cell_types)
      ss << ct << endl;

    ss << "CELL_DATA " << cells.Size() << endl;
    ss << "POINT_DATA " << points.Size() << endl;

    grid_str = ss.str();
  }
Beispiel #18
0
int main(int argc, char** argv) {
    Opt2 opt(argc, argv, "rxcpulma:z:qo:", IntRange(1, 999999), "hexdump=x,cat=c,plain=p,unpack=u,list=l,md5=m,recursive=r,quiet=q,prepend=z,append=a,output=o");
    const bool hexdump   = opt.Has('x', "- produce hexdump");
    const bool cat       = opt.Has('c', "- do not store keys (file names), just cat uncompressed files");
    const bool doNotZip  = opt.Has('p', "- do not use compression");
    const bool unpack    = opt.Has('u', "- unpack archive in current dir");
    const bool list      = opt.Has('l', "- list files in archive");
    const bool listMd5   = opt.Has('m', "- list files in archive with md5");
    const bool recursive = opt.Has('r', "- read all files under each directory, recursively");
    Quiet                = opt.Has('q', "- do not output progress on stderr.");
    Stroka prepend = opt.Arg('z', "<PREFIX> - prepend string to output", 0);
    Stroka append  = opt.Arg('a', "<SUFFIX> - append string to output", 0);
    const Stroka outputf = opt.Arg('o', "<FILE> - output to file instead stdout", 0);
    opt.AutoUsageErr("<file>..."); // "Files or directories to archive."

    SubstGlobal(append, "\\n", "\n");
    SubstGlobal(prepend, "\\n", "\n");

    yvector<TRec> recs;
    for (size_t i = 0; i != opt.Pos.size(); ++i) {
        Stroka path = opt.Pos[i];
        size_t off = 0;
#ifdef _win_
        if (path[0] > 0 && isalpha(path[0]) && path[1] == ':')
            off = 2; // skip drive letter ("d:")
#endif // _win_
        const size_t pos = path.find(':', off);
        TRec cur;
        cur.Path = path.substr(0, pos);
        if (pos != Stroka::npos)
            cur.Prefix = path.substr(pos + 1);
        cur.Recursive = recursive;
        cur.Fix();
        recs.push_back(cur);
    }

    try {
        if (listMd5) {
            for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                ListArchiveMd5(it->Path);
            }
        } else if (list) {
            for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                ListArchive(it->Path);
            }
        } else if (unpack) {
            for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                UnpackArchive(it->Path);
            }
        } else {
            TAutoPtr<TOutputStream> outf(OpenOutput(outputf));
            TOutputStream* out = outf.Get();
            THolder<TOutputStream> hexout;

            if (hexdump) {
                hexout.Reset(new THexOutput(out));
                out = hexout.Get();
            }

            outf->Write(~prepend, +prepend);

            if (cat) {
                for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                    it->Recurse(*out);
                }
            } else {
                TArchiveWriter w(out, !doNotZip);
                for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                    it->Recurse(w);
                }
                w.Finish();
            }

            outf->Write(~append, +append);

            try {
                out->Finish();
            } catch (...) {
            }
        }
    } catch (...) {
        Cerr << CurrentExceptionMessage() << Endl;
        return 1;
    }

    return 0;
}
Beispiel #19
0
int main(int argc, char** argv) {
    Opt2 opt(argc, argv, "rxa:z:q", IntRange(1, 999999), "hexdump=x,recursive=r,quiet=q,prepend=z,append=a");
    bool hexdump         = opt.Has('x', "- produce hexdump");
    const bool recursive = opt.Has('r', "- read all files under each directory, recursively");
    Quiet                = opt.Has('q', "- do not output progress on stderr.");
    const Stroka prepend = opt.Arg('z', "<PREFIX> - prepend string to output verbatim", 0);
    const Stroka append  = opt.Arg('a', "<SUFFIX> - append string to output verbatim", 0);
    opt.AutoUsageErr("<file>..."); // "Files or directories to archive."

    yvector<TRec> recs;
    for (size_t i = 0; i != opt.Pos.size(); ++i) {
        Stroka path = opt.Pos[i];
        size_t off = 0;
#ifdef _win_
        if (path[0] > 0 && isalpha(path[0]) && path[1] == ':')
            off = 2; // skip drive letter ("d:")
#endif // _win_
        const size_t pos = path.find(':', off);
        TRec cur;
        cur.Path = path.substr(0, pos);
        if (pos != Stroka::npos)
            cur.Prefix = path.substr(pos + 1);
        cur.Recursive = recursive;
        cur.Fix();
        recs.push_back(cur);
    }

    try {
        TAutoPtr<TOutputStream> outf(OpenOutput(""));
        TOutputStream* out = outf.Get();
        THolder<TOutputStream> hexout;

        if (hexdump) {
            hexout.Reset(new THexOutput(out));
            out = hexout.Get();
        }

        outf->Write(~prepend, +prepend);

        TArchiveWriter w(out);

        for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
            const TRec& rec = *it;

            if (IsDir(rec.Path)) {
                it->Recurse(w);
            } else {
                Append(w, it->Path, it->Prefix + "/" + GetFile(it->Path));
            }
        }

        w.Finish();
        outf->Write(~append, +append);
        out->Finish();
    } catch (...) {
        Cerr << CurrentExceptionMessage() << Endl;

        return 1;
    }

    return 0;
}