Exemple #1
0
bool ZIntCuboidFace::contains(int x, int y, int z) const
{
  int u = 0;
  int v = 0;
  int w = 0;

  switch (getAxis()) {
  case NeuTube::X_AXIS:
    u = y;
    v = z;
    w = x;
    break;
  case NeuTube::Y_AXIS:
    u = x;
    v = z;
    w = y;
    break;
  case NeuTube::Z_AXIS:
    u = x;
    v = y;
    w = z;
    break;
  }

  if (w != getPlanePosition()) {
    return false;
  }

  return getLowerBound(0) <= u && getUpperBound(0) >= u &&
      getLowerBound(1) <= v && getUpperBound(1) >= v;
}
Exemple #2
0
EdgeWeight ALT::findShortestPathDistance(Graph& graph, NodeID source, NodeID target)
{
    BinaryMinHeap<EdgeWeight,NodeDistancePair> pqueue;
    std::vector<bool> isNodeSettled(graph.getNumNodes(),false);
    
//     EdgeWeight adjNodeWgt;
    EdgeWeight  minDist, sourceToAdjNodeDist, distanceToTarget = 0;
    NodeID minDistNodeID, adjNode;
    int adjListStart, adjListSize;
    
    // Initialize priority queue with source node
    EdgeWeight minSourceTargetDist = getLowerBound(source,target);
    pqueue.insert(NodeDistancePair(source,0),minSourceTargetDist);
    
    while (pqueue.size() > 0) {
        // Extract and remove node with smallest possible distance to target
        // and mark it as "settled" so we do not inspect again
        // Note: In A* search this willl still lead to a optimal solution
        // if the heuristic function we use is consistent (i.e. never overestimates)
        NodeDistancePair minElement = pqueue.extractMinElement();
        minDistNodeID = minElement.first;
        if (!isNodeSettled[minDistNodeID]) {
            isNodeSettled[minDistNodeID] = true; // Mark it as "settled" so we can avoid later
            minDist = minElement.second;
            
            if (minDistNodeID == target) {
                // If the minimum is the target we have finished searching
                distanceToTarget = minDist;
                break;
            }

            // Inspect each neighbour and update pqueue using edge weights
            adjListStart = graph.getEdgeListStartIndex(minDistNodeID);
            adjListSize = graph.getEdgeListSize(minDistNodeID);
            
            for (int i = adjListStart; i < adjListSize; ++i) {
                adjNode = graph.edges[i].first;
                // Only consider neighbours we haven't already settled
                if (!isNodeSettled[adjNode]) {
//                     // Heuristic Consistency Test Output
//                     EdgeWeight currentToTargetEst = getLowerBound(minDistNodeID,target);
//                     EdgeWeight neighbourToTargetEst = getLowerBound(adjNode,target);
//                     if (currentToTargetEst > graph.edges[i].second+neighbourToTargetEst) {
//                         std::cout << "currentToTargetEst = " << currentToTargetEst << std::endl;
//                         std::cout << "adjNodeWgt = " << graph.edges[i].second << std::endl;
//                         std::cout << "neighbourToTargetEst = " << neighbourToTargetEst << std::endl;
//                         std::cout << "Diff = " << currentToTargetEst - graph.edges[i].second - neighbourToTargetEst << std::endl;
//                     }
                    //assert (currentToTargetEst <= adjNodeWgt+neighbourToTargetEst && "Heuristic function is not consistent");
                    
                    sourceToAdjNodeDist = minDist + graph.edges[i].second;
                    minSourceTargetDist = sourceToAdjNodeDist + getLowerBound(adjNode,target);
                    pqueue.insert(NodeDistancePair(adjNode,sourceToAdjNodeDist),minSourceTargetDist);
                }
            }
        }
    }

    return distanceToTarget;
}
Exemple #3
0
// --------------------------------------------------------------------- //
void
DecompVar::print(ostream*    os,
                 DecompApp* app) const
{
   double lb = getLowerBound();
   double ub = getUpperBound();
   (*os) << "\nVAR c: " << m_origCost
         << " rc: "     << m_redCost
         << " eff: "    << m_effCnt;

   if (lb > -DecompInf) {
      (*os) << " lb:  "    << getLowerBound();
   } else {
      (*os) << " lb: -INF";
   }

   if (ub < DecompInf) {
      (*os) << " ub:  "    << getUpperBound();
   } else {
      (*os) << " ub:  INF";
   }

   (*os) << "\n";
   UtilPrintPackedVector(m_s, os, app);
}
Exemple #4
0
bool ZIntCuboidFace::hasOverlap(const ZIntCuboidFace &face) const
{
  if (getAxis() != face.getAxis() ||
      getPlanePosition() != face.getPlanePosition()) {
    return false;
  }

  if (getLowerBound(0) > face.getUpperBound(0)) {
    return false;
  }

  if (getLowerBound(1) > face.getUpperBound(1)) {
    return false;
  }

  if (face.getLowerBound(0) > getUpperBound(0)) {
    return false;
  }

  if (face.getLowerBound(1) > getUpperBound(1)) {
    return false;
  }

  return true;
}
Exemple #5
0
ZIntCuboidFace::Corner ZIntCuboidFace::getCorner(int index) const
{
  switch (index) {
  case 0:
    return getFirstCorner();
  case 1:
    return Corner(getUpperBound(0), getLowerBound(1));
  case 2:
    return Corner(getLowerBound(0), getUpperBound(1));
  case 3:
    return getLastCorner();
  }

  return Corner(0, 0);
}
bool ConstraintBSpline::haveVariableBoundsChanged() const
{
    if (variables.size() != storedVariables.size())
        return true;

    for (unsigned int i = 0; i < variables.size()-1; i++)
    {
        auto var = *variables.at(i);
        auto svar = storedVariables.at(i);

        if (var.getUpperBound() != svar.getUpperBound()
                || var.getLowerBound() != svar.getLowerBound())
            return true;
    }

    return false;
}
Exemple #7
0
 vector<int> searchRange3(int A[], int n, int target) {
     vector<int> res(2, -1);
     int lower = getLowerBound(A, n, target);
     int upper = getUpperBound(A, n, target);
     if (lower <= upper)
     {
         res[0] = lower;
         res[1] = upper;
     }
     return res;
 }
Exemple #8
0
 vector<int> searchRange(vector<int>& nums, int target) {
     int n = nums.size();
     vector<int> res(2, -1);
     int lower = getLowerBound(nums, target);
     int upper = getUpperBound(nums, target);
     if(lower <= upper) {
         res[0] = lower;
         res[1] = upper;
     }
     return res;
 }
Exemple #9
0
bool CFitItem::updateBounds(std::vector<COptItem * >::iterator it)
{
  while (*it != this)
    {
      if (mpLowerObject && (getLowerBound() == (*it)->getObjectCN()))
        mpLowerBound = &static_cast<CFitItem *>(*it)->getLocalValue();

      if (mpUpperObject && (getUpperBound() == (*it)->getObjectCN()))
        mpUpperBound = &static_cast<CFitItem *>(*it)->getLocalValue();

      ++it;
    }

  return true;
}
Exemple #10
0
bool GEdge::computeDistanceFromMeshToGeometry (double &d2, double &dmax)
{
  d2 = 0.0; dmax = 0.0;
  if (geomType() == Line) return true;
  if (!lines.size())return false;
  IntPt *pts;
  int npts;
  lines[0]->getIntegrationPoints(2*lines[0]->getPolynomialOrder(), &npts, &pts);

  for (unsigned int i = 0; i < lines.size(); i++){
    MLine *l = lines[i];
    double t[256];

    for (int j=0; j< l->getNumVertices();j++){
      MVertex *v = l->getVertex(j);
      if (v->onWhat() == getBeginVertex()){
	t[j] = getLowerBound();
      }
      else if (v->onWhat() == getEndVertex()){
	t[j] = getUpperBound();
      }
      else {
	v->getParameter(0,t[j]);
      }
    }
    for (int j=0;j<npts;j++){
      SPoint3 p;
      l->pnt(pts[j].pt[0],0,0,p);
      double tinit = l->interpolate(t,pts[j].pt[0],0,0);
      GPoint pc = closestPoint(p, tinit);
      if (!pc.succeeded())continue;
      double dsq =
	(pc.x()-p.x())*(pc.x()-p.x()) +
	(pc.y()-p.y())*(pc.y()-p.y()) +
	(pc.z()-p.z())*(pc.z()-p.z());
      d2 += pts[i].weight * fabs(l->getJacobianDeterminant(pts[j].pt[0],0,0)) * dsq;
      dmax = std::max(dmax,sqrt(dsq));
    }
  }
  d2 = sqrt(d2);
  return true;
}
Exemple #11
0
ZIntCuboidFaceArray ZIntCuboidFace::cropBy(const ZIntCuboidFace &face) const
{
  ZIntCuboidFaceArray faceArray;
  if (hasOverlap(face)) {
    if (isWithin(face)) {
      return faceArray;
    } else {
      ZIntCuboidFace subface(getAxis(), isNormalPositive());
      subface.setZ(getPlanePosition());

      subface.set(getFirstCorner(),
                  Corner(getUpperBound(0), face.getLowerBound(1) - 1));
      faceArray.appendValid(subface);

      subface.set(Corner(getLowerBound(0),
                         imax2(getLowerBound(1), face.getLowerBound(1))),
                  Corner(face.getLowerBound(0) - 1, getUpperBound(1)));
      faceArray.appendValid(subface);

      subface.set(Corner(face.getUpperBound(0) + 1,
                         imax2(getLowerBound(1), face.getLowerBound(1))),
                  getLastCorner());
      faceArray.appendValid(subface);

      subface.set(Corner(imax2(getLowerBound(0), face.getLowerBound(0)),
                         face.getUpperBound(1) + 1),
                  Corner(imin2(getUpperBound(0), face.getUpperBound(0)),
                         getUpperBound(1)));
      faceArray.appendValid(subface);
    }
#if 0
    else if (face.isWithin(*this)) {
      ZIntCuboidFace subface(getAxis(), isNormalPositive());
      secondCorner.set(getUpperBound(0), face.getLowerBound(1));
      subface.set(getFirstCorner(), secondCorner);
      faceArray.appendValid(subface);

      subface.set(Corner(getLowerBound(0), face.getLowerBound(1)),
                  face.getCorner(2));
      faceArray.appendValid(subface);

      subface.set(Corner(getLowerBound(0), face.getUpperBound(1)),
                  getLastCorner());
      faceArray.appendValid(subface);
    } else {

    }
#endif
  } else {
void slave_computation(double start, long iterations)
{	
	int i;
	double size = 1.0/strips;
	long localSum[2]={0,0};
	double xleft, xright;
	long sum[2]={0,0};
	for (i=0; i<iterations; i++)
	{
		xleft=start+i*size;
		xright=start+(i+1)*size;
		localSum[0]+=getUpperBound(xleft);
		localSum[1]+=getLowerBound(xright);
	}
	MPI_Reduce(&localSum,&sum,2,MPI_LONG,MPI_SUM,nprocs-1,MPI_COMM_WORLD);
	//printf("id: %d, sum: %li \n", myid,sum[0]);
	if(myid == nprocs-1)
	{
		double result = (sum[0]+sum[1])/2.0*(size*size);
		printf("Integration result: %.8f", result);
	}
}
Exemple #13
0
returnValue VariablesGrid::initializeFromBounds( )
{
    uint run1, run2;

    for( run1 = 0; run1 < getNumPoints(); run1++ ){
        for( run2 = 0; run2 < getNumValues(); run2++ ){

            if( fabs( getLowerBound(run1,run2) ) <  0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) <  0.999*INFTY ){

                operator()(run1,run2) = 0.5*( getLowerBound(run1,run2) + getUpperBound(run1,run2) );

            }

            if( fabs( getLowerBound(run1,run2) ) >= 0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) <  0.999*INFTY ){

                operator()(run1,run2) = getUpperBound(run1,run2);
            }

            if( fabs( getLowerBound(run1,run2) ) <  0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) >= 0.999*INFTY ){

                operator()(run1,run2) = getLowerBound(run1,run2);
            }

            if( fabs( getLowerBound(run1,run2) ) >= 0.999*INFTY &&
                fabs( getUpperBound(run1,run2) ) >= 0.999*INFTY ){

                operator()(run1,run2) = 0.0;
            }
        }
    }

	return SUCCESSFUL_RETURN;
}
Exemple #14
0
Path ALT::findShortestPath(Graph& graph, NodeID source, NodeID target, 
                                   std::vector<NodeID>& shortestPathTree)
{
    // We assume shortestPathTree has been resized for the size of the graph
    // However it does not need to have zero values as we overwrite them
    
    BinaryMinHeap<EdgeWeight,AStarHeapElement> pqueue;
    std::vector<bool> isNodeSettled(graph.getNumNodes(),false);
    
//     EdgeWeight adjNodeWgt;
    EdgeWeight  minDist, sourceToAdjNodeDist, distanceToTarget = 0;
    NodeID minDistNodeID, adjNode;
    int adjListStart, adjListSize;
    
    // Initialize priority queue with source node
    EdgeWeight minSourceTargetDist = getLowerBound(source,target);
    pqueue.insert(AStarHeapElement(source,constants::UNUSED_NODE_ID,0),minSourceTargetDist);
    
    while (pqueue.size() > 0) {
        // Extract and remove node with smallest possible distance to target
        // and mark it as "settled" so we do not inspect again
        // Note: In A* search this willl still lead to a optimal solution
        // if the heuristic function we use is consistent (i.e. never overestimates)
        AStarHeapElement minElement = pqueue.extractMinElement();
        minDistNodeID = minElement.node;
        if (!isNodeSettled[minDistNodeID]) {
            isNodeSettled[minDistNodeID] = true; // Mark it as "settled" so we can avoid later
            minDist = minElement.sourceNodeDist;
            shortestPathTree[minDistNodeID] = minElement.predecessor;
            
            if (minDistNodeID == target) {
                // If the minimum is the target we have finished searching
                distanceToTarget = minDist;
                break;
            }

            // Inspect each neighbour and update pqueue using edge weights
            adjListStart = graph.getEdgeListStartIndex(minDistNodeID);
            adjListSize = graph.getEdgeListSize(minDistNodeID);
            
            for (int i = adjListStart; i < adjListSize; ++i) {
                adjNode = graph.edges[i].first;
                // Only consider neighbours we haven't already settled
                if (!isNodeSettled[adjNode]) {
//                     // Heuristic Consistency Test Output
//                     EdgeWeight currentToTargetEst = getLowerBound(minDistNodeID,target);
//                     EdgeWeight neighbourToTargetEst = getLowerBound(adjNode,target);
//                     if (currentToTargetEst > graph.edges[i].second+neighbourToTargetEst) {
//                         std::cout << "currentToTargetEst = " << currentToTargetEst << std::endl;
//                         std::cout << "adjNodeWgt = " << graph.edges[i].second << std::endl;
//                         std::cout << "neighbourToTargetEst = " << neighbourToTargetEst << std::endl;
//                         std::cout << "Diff = " << currentToTargetEst - graph.edges[i].second - neighbourToTargetEst << std::endl;
//                     }
                    //assert (currentToTargetEst <= adjNodeWgt+neighbourToTargetEst && "Heuristic function is not consistent");
                    
                    sourceToAdjNodeDist = minDist + graph.edges[i].second;
                    minSourceTargetDist = sourceToAdjNodeDist + getLowerBound(adjNode,target);
                    pqueue.insert(AStarHeapElement(adjNode,minDistNodeID,sourceToAdjNodeDist),minSourceTargetDist);
                }
            }
        }
    }
    
    // Retrieve and return shortest path
    Path path(source, true, distanceToTarget);
    for (NodeID currentNode = target; currentNode != source; currentNode = shortestPathTree[currentNode]) {
        path.addToBeginning(currentNode);
    }
    
    return path;
}
Exemple #15
0
bool BoundingBox::overlaps(BoundingBox *other) {
  return ( !(getUpperBound() > other->getLowerBound()) &&
	   !(getLowerBound() < other-> getUpperBound()) &&
	   !(getLeftBound() > other->getRightBound()) &&
	   !(getRightBound() < other->getLeftBound()) );
}
Exemple #16
0
inline unsigned int FMPWPartTmpl<GainTmpl>::
doPartitionInternal(vector<unsigned char>& part) 
{
  typedef FMPartTmpl<FMBiPartCore, GainTmpl> PWPartMgrType; 
  typedef FMPartTmpl4<FMKWayPartCore4, FMKWayGainMgr2> RefineType; 

  unsigned int cost1 = _initCost;
  unsigned int cost = _initCost;

  RefineType rfMgr(getParam());
  rfMgr.setBalanceTol(getBalanceTol());
  rfMgr.setPValue(1);
  rfMgr.setQValue(10);
  rfMgr.setVerbosity(getVerbosity());
  rfMgr.setBoundType(getBoundType());
  rfMgr.noNeedSetHighFanoutNets();

  while (1) {
    initGrouping2();
    getNetlist().pairWisePhase1(part, _groupMap, _sGVec);
    //xxx int cost3 = cost;
    cost = cost1;

    for (unsigned int j=0; j<_numGroups; ++j) {
      const FMParam param(*_sGVec[j]);
      PWPartMgrType PWMgr(param);
      //xxx PWMgr.setBalanceTol(getBalanceTol());
      PWMgr.setUpperBound(getUpperBound());
      PWMgr.setLowerBound(getLowerBound());
      // PWMgr.setPValue(_pvalue);
      // PWMgr.setQValue(_qvalue);
      PWMgr.setVerbosity(getVerbosity());
      //xxx PWMgr.setBoundType(getBoundType());
      PWMgr.noNeedSetHighFanoutNets();
      PWMgr.setNoInit(cost);
      vector<unsigned char> pw_part;
      projectUp(part, pw_part, j);
      // cost = PWMgr.doPartitionOne(pw_part);
      boost::array<int, 64>& diff = getDiff();
      const unsigned int part0 = _groupInvMap[j];
      const unsigned int part1 = _moveTo[part0];
      int diff2[2];
      diff2[0] = diff[part0];
      diff2[1] = diff[part1];
      PWMgr.setDiff(diff2);
      cost = PWMgr.doPartitionOne4(pw_part);
      // PWMgr.doPartition(pw_part, 1);
      // cost = PWMgr.getBestCost();
      projectDown(part, pw_part, j);
      int* diff3 = PWMgr.getDiff();
      diff[part0] = diff3[0];
      diff[part1] = diff3[1];
      delete _sGVec[j];
    }
    // printDiff();
    // std::cout << "cost = " << cost << std::endl;

    assert(cost == getNetlist().cutCost(part, getNumPartitions()));
    //xxx initDiff(part);  

    rfMgr.setNoInit(cost); // only refine the solution
    rfMgr.setDiff(getDiff());
    cost1 = rfMgr.doPartitionOne4(part);
    // rfMgr.doPartition(part, 1);
    // cost1 = rfMgr.getBestCost();
    assert(cost1 == getNetlist().cutCost(part, getNumPartitions()));
    setDiff(rfMgr.getDiff());
    // printDiff();
    // std::cout << "cost1 = " << cost1 << std::endl;

    if (cost1 >= cost) break;
  }


  return cost1;
}
Exemple #17
0
bool ZIntCuboidFace::contains(ZIntCuboidFace::Corner pt) const
{
  return (pt.getX() >= getLowerBound(0) && pt.getX() <= getUpperBound(0) &&
          pt.getY() >= getLowerBound(1) && pt.getY() <= getUpperBound(1));
}
Exemple #18
0
bool ZIntCuboidFace::isValid() const
{
  return (getLowerBound(0) <= getUpperBound(0)) &&
      (getLowerBound(1) <= getUpperBound(1));
}