Exemplo n.º 1
0
static property generate_property(ast_atom const &p, bool goal)
{
  predicated_real pr(p.real, p.real2, p.type);
  output_reals.insert(pr);
  switch (p.type) {
  case PRED_FIX:
  case PRED_FLT:
    input_reals.insert(pr);
    return property(pr, p.cst);
  case PRED_EQL:
    register_approx(p.real, p.real2);
    // no break
  case PRED_NZR:
    input_reals.insert(pr);
    return property(pr);
  case PRED_BND:
  case PRED_ABS:
  case PRED_REL:
    break;
  }

  property r(pr);
  if (p.lower || p.upper)
  {
    input_reals.insert(pr);
    if (p.real2)
      register_approx(p.real, p.real2);
    else
      check_approx(p.real);

    interval &bnd = r.bnd();
    bnd = create_interval(p.lower, p.upper, !goal);
    if (is_empty(bnd))
    {
      std::cerr << "Error: the range of " << dump_real_short(pr)
                << " is an empty interval.\n";
      exit(1);
    }
    if (pr.real2() && lower(bnd) <= number(-1))
    {
      std::cerr << "Error: the range of " << dump_real_short(pr)
                << " contains values smaller or equal to -1.\n";
      exit(1);
    }
  }
  else if (!goal)
  {
    std::cerr << "Error: undefined intervals are restricted to conclusions.\n";
    exit(1);
  }
  else goal_reduction = false;
  return r;
}
Exemplo n.º 2
0
static clusternode* create_node(int start, int end, int id) {
    clusternode *new_node = ALLOC(clusternode);
    
    new_node->start     = start;
    new_node->end       = end;
    new_node->interval_head = create_interval(start, end, id);
    new_node->interval_tail = new_node->interval_head;
    new_node->num_ivals = 1;
    new_node->left      = NULL;
    new_node->right     = NULL;
    
    double uniform = ((double)rand()) / (RAND_MAX);
    if (uniform == 1.0)
        uniform = 0;
    new_node->priority = (int)ceil( (-1.0 / log(.5)) * log( -1.0 / (uniform - 1)));
    
    return new_node;
}
Exemplo n.º 3
0
/* Insert based on the start position of intervals */
clusternode* clusternode_insert(clustertree *tree, clusternode *node, int start, int end, int id) {
    int oldstart;
    int oldend;
    interval* ival;
    
    // printf("Inserting %d %d %d\n", start, end, id);
    if (node == NULL) {
        node = create_node(start, end, id);
        
    } else if ( (start - tree->max_dist) > node->end ) { /* We're to the right of this cluster */
        node->right = clusternode_insert(tree, node->right, start, end, id);
        if (node->priority < node->right->priority) cluster_rotateleft(&node);
    
    } else if ( (end + tree->max_dist) < node->start) { /* We're to the left of this cluster */
        node->left = clusternode_insert(tree, node->left, start, end, id);
        if (node->priority < node->left->priority) cluster_rotateright(&node);
                        
    } else { /* We're in the range of this cluster */
        /* Update the start and end to match to new values */
        oldstart    = node->start;
        oldend      = node->end;
        node->start = min(start, node->start);
        node->end   = max(end, node->end);
        ival = create_interval(start, end, id);
        ival->next = node->interval_head; /* Add this interval as the head of the interval list */
        node->interval_head = ival;
        node->num_ivals += 1;
                
        if ( oldstart > node->start && node->left != NULL ) { /* New interval added to the start, and there's a left child */
            cluster_fixup(tree, &(node->left), &node);
        }
        if ( oldend < node->end && node->right != NULL ) { /* New interval added to the end, and there's a right child */
            cluster_fixup(tree, &(node->right), &node);
        }
    }
    return node;
}