Exemplo n.º 1
0
// Split this interval at pos and return the rest. Pos must be a location
// that ensures both shorter intervals are nonempty. If keep_uses is set,Uses
// exactly at the end of the first interval will stay with the first part.
Interval* Interval::split(unsigned pos, bool keep_uses) {
  assert(pos > start() && pos < end()); // both parts will be non-empty
  auto leader = this->leader();
  Interval* child = smart_new<Interval>(leader);
  child->next = next;
  next = child;
  // advance r1 to the first range we want in child; maybe split a range.
  auto r1 = ranges.begin(), r2 = ranges.end();
  while (r1->end <= pos) r1++;
  if (pos > r1->start) { // split r at pos
    child->ranges.push_back({pos, r1->end});
    r1->end = pos;
    r1++;
  }
  child->ranges.insert(child->ranges.end(), r1, r2);
  ranges.erase(r1, r2);
  // advance u1 to the first use position in child, then copy u1..end to child.
  auto u1 = uses.begin(), u2 = uses.end();
  if (keep_uses) {
    while (u1 != u2 && u1->pos <= end()) u1++;
  } else {
    while (u1 != u2 && u1->pos < child->start()) u1++;
  }
  child->uses.insert(child->uses.end(), u1, u2);
  uses.erase(u1, u2);
  return child;
}
Exemplo n.º 2
0
void bisectionMethod(Interval const &interval, double const &eps) {
	double left = interval.start();
	double right = interval.end();
	double middle = (right + left) / 2;

	int n = 0;

	while (abs(left - right) > 2 * eps) {
		if (FuncClass::func(left) * FuncClass::func(middle) > 0)
			left = middle;
		else
			right = middle;
		middle = (right + left) / 2;
		
		n++;
	}

	cout << "Bisection method\n";
	cout << "Step: " << n << "\n";
	cout << "Approximated solution: " << middle << "\n";
	cout << "Discrepansy module: " << abs(FuncClass::func(middle)) << "\n\n";
}
Exemplo n.º 3
0
// Note: this is considerably more efficient in the case where intervals are added
// smallest first.
void IntervalList::addInterval(Interval interval)
{
  if(m_list.size() == 0)
  {
    m_list.append(interval);
    return;
  }
  
  bool added = false;
  QList<int> deleteList;

  for(int i = m_list.size() - 1; i >= 0 ; i--)
  {
    // if new interval is completely higher than this interval
    if(interval.start() > m_list.at(i).end() + 1)
    {
      // add new interval as a seperate interval
      m_list.append(interval);
      added = true;
      break;
    }
    // else if the new interval can be merged with this interval
    else if(m_list.at(i).canMerge(interval))
    {
      // for each interval in the list before and including this one
      for(int j = i; j >= 0; j--)
      {
        // if it can be merged into the new interval
        if(m_list.at(j).canMerge(interval))
        {
          // do it
          interval.merge(m_list.at(j));
          // then add its index to the list of intervals to be deleted
          deleteList.append(j);
        }
        // else if it cant, there is no need to continue checking whether 
        // any other intervals can alse be merged
        else
        {
          break;
        }
      }
      // insert the new large interval in the correct place
      m_list.insert(i+1, interval);
      added = true;
      break;
    }
  }
  // if deleteList has any elements, delete intervals at those indices
  if(deleteList.size() > 0)
  {
    qSort(deleteList);
      
    for(int i = deleteList.size() - 1; i >=0 ; i--)
    {
      m_list.removeAt(deleteList[i]);
    }
  }
  // if still not assigned, add to the beginning 
  if(!added)
  {
    m_list.insert(0, interval);
  }
}
Exemplo n.º 4
0
    bool Solver::calcStabilityForRowC()
    {
        m_stabilityRowC.resize(m_width, Interval());
        for(size_t j=0; j < m_width; j++)
        {
            Interval vals;

            if(m_variableType[j] == VariableMain)
            {
                size_t basisi;
                for(basisi=0; basisi < m_height; basisi++)
                {
                    if(m_columnBasis[basisi] == j)
                        break;
                }

                // basis variable
                if(basisi != m_height)
                {
                    // we can't change basis variables without changing rowD
                    vals.setStart(0);
                    vals.setEnd(0);

                    /*
                    for(size_t jj=0; jj < m_width; jj++)
                    {
                        if(checkEquals(m_rowD[jj], 0.0) ||
                           checkEquals(m_matrixA[basisi][jj], 0.0))
                            continue;

                        double deltac = m_rowD[jj] / m_matrixA[basisi][jj];

                        if(m_funcType == OptimizeToMin)
                            deltac = -deltac;

                        if(deltac < 0)
                        {
                            if(deltac > vals.start())
                                 vals.setStart(deltac);
                        }
                        else if(deltac > 0)
                        {
                            if(deltac < vals.end())
                                 vals.setEnd(deltac);
                        }
                    }*/
                }
                else // free variable
                {
                    double deltac = m_rowD[j];

                    if(m_funcType == OptimizeToMax)
                        deltac = -deltac;

                    if(deltac > 0)
                        vals.setEnd(deltac);
                    else if(deltac < 0)
                        vals.setStart(deltac);
                    else
                    {
                        vals.setStart(deltac);
                        vals.setEnd(deltac);
                    }
                }

                vals.setStart(m_rowC[j] + vals.start());
                vals.setEnd(m_rowC[j] + vals.end());
            }

            m_stabilityRowC[j] = vals;
        }

        return true;
    }
Exemplo n.º 5
0
void check_interval(const Interval& actual, const Interval& truth) {
  BOOST_CHECK_EQUAL(actual.chr(), truth.chr());
  BOOST_CHECK_EQUAL(actual.start(), truth.start());
  BOOST_CHECK_EQUAL(actual.stop(), truth.stop());
}
Exemplo n.º 6
0
string ReferenceMap::get_sequence(const Interval& interval, const bool reverse_strand) const {
  const auto& seq = this->at(interval.chr());
  auto result = seq.substr(interval.start()-1, interval.size());
  return reverse_strand ? utils::complement(result) : result;
}