Ejemplo n.º 1
0
Archivo: dm.c Proyecto: graydon/ltsmin
static inline int
row_costs_ (matrix_t *r, matrix_t *mayw, int row)
{
    HREassert(
                dm_ncols(r) == dm_ncols(mayw) &&
                dm_nrows(r) == dm_nrows(mayw), "matrix sizes do not match");
    
    int writes = 0;
    int cost = 0;
    for (int i = 0; i < dm_ncols(r); i++) {
        if (dm_is_set(mayw, row, i)) writes++;
        if (dm_is_set(r, row, i)) cost += writes;
    }

    cost += max(last_ (mayw, row), last_ (r, row)) - min(first_ (mayw, row), first_ (r, row)) + 1;

    return cost;

}
Ejemplo n.º 2
0
 const child_node& child_node_list::front() const
 {
     if (empty())
     {
         throw bad_dom_operation("front() called on an empty child_node_list");
     }
     else
     {
         return *first_();
     }
 }
void ClientHandler::BeginTracing() {
  if (CefCurrentlyOn(TID_UI)) {
    class Client : public CefTraceClient,
                   public CefRunFileDialogCallback {
     public:
      explicit Client(CefRefPtr<ClientHandler> handler)
          : handler_(handler),
            trace_data_("{\"traceEvents\":["),
            first_(true) {
      }

      virtual void OnTraceDataCollected(const char* fragment,
                                        size_t fragment_size) OVERRIDE {
        if (first_)
          first_ = false;
        else
          trace_data_.append(",");
        trace_data_.append(fragment, fragment_size);
      }

      virtual void OnEndTracingComplete() OVERRIDE {
        REQUIRE_UI_THREAD();
        trace_data_.append("]}");

        static const char kDefaultFileName[] = "trace.txt";
        std::string path = handler_->GetDownloadPath(kDefaultFileName);
        if (path.empty())
          path = kDefaultFileName;

        handler_->GetBrowser()->GetHost()->RunFileDialog(
            FILE_DIALOG_SAVE, CefString(), path, std::vector<CefString>(),
            this);
      }

      virtual void OnFileDialogDismissed(
          CefRefPtr<CefBrowserHost> browser_host,
          const std::vector<CefString>& file_paths) OVERRIDE {
        if (!file_paths.empty())
          handler_->Save(file_paths.front(), trace_data_);
      }

     private:
      CefRefPtr<ClientHandler> handler_;
      std::string trace_data_;
      bool first_;

      IMPLEMENT_REFCOUNTING(Callback);
    };
Ejemplo n.º 4
0
 const child_node& child_node_list::back() const
 {
     if (empty())
     {
         throw bad_dom_operation("back() called on an empty child_node_list");
     }
     else
     {
         basic_node_ptr<const child_node> last(first_());
         while (last->next_sibling() != 0)
         {
             last = last->next_sibling();
         }
         return *last;
     }
 }
Ejemplo n.º 5
0
 child_node_list::const_iterator child_node_list::begin() const
 {
     return const_iterator( first_() );
 }
Ejemplo n.º 6
0
 child_node_list::iterator child_node_list::begin()
 {
     return iterator( const_cast<child_node*>(first_()) );
 }
Ejemplo n.º 7
0
 bool child_node_list::empty() const
 {
     return (first_() == 0);
 }
Ejemplo n.º 8
0
Archivo: dm.c Proyecto: graydon/ltsmin
int
dm_optimize (matrix_t *r, matrix_t *mayw, matrix_t *mustw)
{
    HREassert(
                dm_ncols(r) == dm_ncols(mayw) &&
                dm_nrows(r) == dm_nrows(mayw) &&
                dm_ncols(r) == dm_ncols(mustw) &&
                dm_nrows(r) == dm_nrows(mustw), "matrix sizes do not match");
    
    matrix_t* test = RTmalloc(sizeof(matrix_t));
    dm_create(test, dm_nrows(r), dm_ncols(r));
    dm_copy(r, test);
    dm_apply_or(test, mayw);

    int                 d_rot[dm_ncols (r)];
    permutation_group_t rot;

    int best_i = 0,
    best_j = 0,
    min = cost_ (r, mayw),
    last_min = 0;
    int i, j, c, k, d;

    int firsts[dm_nrows(r)];
    int lasts[dm_nrows(r)];

    while (last_min != min) {
        last_min = min;

        // initialize first and last integers per row
        for (i=0; i<dm_nrows(r); i++) {
            firsts[i] = first_(test,i);
            lasts[i]  = last_(test,i);
        }

        // find best rotation
        for (i = 0; i < dm_ncols (r); i++) {
            for (j = 0; j < dm_ncols (r); j++) {
                if (i != j) {
                    c=estimate_cost(test,i,j,firsts,lasts);
                    if (c < min) {
                        min = c;
                        best_i = i;
                        best_j = j;
                    }
                }
            }
        }

        // rotate
        if (best_i != best_j) {
            d = best_i < best_j ? 1 : -1;
            dm_create_permutation_group (&rot, dm_ncols (r), d_rot);
            for (k = best_i; k != best_j; k += d)
                dm_add_to_permutation_group (&rot, k);
            dm_add_to_permutation_group (&rot, best_j);
            dm_permute_cols (r, &rot);
            dm_permute_cols (mayw, &rot);
            dm_permute_cols (mustw, &rot);
            dm_permute_cols (test, &rot);
            dm_free_permutation_group (&rot);

            DMDBG (printf("best rotation: %d-%d, costs %d\n", best_i, best_j, min));
            DMDBG (dm_print_combined (stdout, r, mayw, mustw));

            best_i = best_j = 0;
        }
    }
    DMDBG (printf ("cost: %d ", cost_ (r, mayw)));
    dm_free(test);
    return 0;
}