Example #1
0
void ConnectorLine::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
   event->accept();

   int myindex = m_pConnector->lineList()->indexOf( this );

   if( myindex == 0 )
       m_pConnector->addConLine( p1().x(), p1().y(), p1().x(), p1().y(), myindex );

   else if( myindex == m_pConnector->lineList()->size()-1 )
       m_pConnector->addConLine( p2().x(), p2().y(), p2().x(), p2().y(), myindex + 1 );

   QPoint delta = togrid( event->scenePos() ).toPoint() - togrid(event->lastScenePos()).toPoint();

   moveLine( delta );
}
Example #2
0
void ConnectorLine::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
   if( event->button() == Qt::LeftButton && m_pConnector->endPin() ) // If havent end pin means try to connect myself
   {
       if( event->modifiers() == Qt::ControlModifier )
       {
           event->accept();

           if  ( dy() == 0 )   setCursor( Qt::SplitVCursor );
           else                setCursor( Qt::SplitHCursor );

           grabMouse();
       }
       else     // Add a graphic node here
       {
           int index;
           int myindex = m_pConnector->lineList()->indexOf( this );
           QPoint point1 = togrid(event->scenePos()).toPoint();

           ConnectorLine* line;

           if( ( (dy() == 0) && ( abs( point1.x()-m_p2X ) < 15 ) )                // point near the p2 corner
             ||( (dx() == 0) && ( abs( point1.y()-m_p2Y ) < 15 ) ) )
           {
               if ( myindex == m_pConnector->lineList()->size()-1 )
               {
                   event->ignore();
                   return;
               }
               event->accept();
               point1 = p2();
               index = myindex+1;
               line = m_pConnector->lineList()->at( index );
           }
           else if( ( (dy() == 0) && ( abs( point1.x()-m_p1X ) < 15 ) )           // point near the p1 corner
                 || ( (dx() == 0) && ( abs( point1.y()-m_p1Y ) < 15 ) ) )
           {
               if ( myindex == 0 )
               {
                   event->ignore();
                   return;
               }
               event->accept();
               point1 = p1();
               line = this;
               index = myindex;
           }
           else                                                                    // split this line in two
           {
               event->accept();

               if ( dy() == 0 )    point1.setY( m_p1Y );
               else                point1.setX( m_p1X );

               index = myindex+1;

               line = new ConnectorLine( point1.x(), point1.y(), m_p2X, p2().y(), m_pConnector );
               m_pConnector->addConLine( line, index );
           }

           QString type = QString("Node");
           QString id = type;
           id.append( "-" );
           id.append( Circuit::self()->newSceneId() );

           Node* node = new Node( 0, type, id );                   // Now add the Node
           node->setPos( point1.x(), point1.y());
           Circuit::self()->addItem( node );

           bool pauseSim = Simulator::self()->isRunning();
           if( pauseSim )  Simulator::self()->pauseSim();

           //qDebug() << "line constarted" << Circuit::self()->is_constarted() << Circuit::self();

           m_pConnector->splitCon( index, node->getPin(0), node->getPin(2) );
           eNode* enode = m_pConnector->enode();    // get the eNode from my connector
           node->getPin(1)->setEnode( enode );

           if( Circuit::self()->is_constarted() )   // A Connector wants to connect here (ends in a node)
           {
               //Circuit::self()->getNewConnector()->setEnode( enode ); // Set the eNode to the new connector
               Circuit::self()->closeconnector( node->getPin(1) );
           }
           else                                     // A new Connector created here (starts in a node)
           {
               Circuit::self()->newconnector( node->getPin(1) );      // start a new connector
               //Circuit::self()->getNewConnector()->setEnode( enode ); // Set the eNode to the new connector
           }

           if( pauseSim ) Simulator::self()->runContinuous();
       }
   }
   else event->ignore();
}
Example #3
0
void Alg7::strategy()
{
  // double bestSize0, bestSize1, bestSize2;
  computeInfo *c;
  int numAssigned;
  processorInfo* goodP[3][3][2];  // goodP[# of real patches][# of proxies]
  processorInfo* poorP[3][3][2];  // fallback option

  double startTime = CmiWallTimer();

  // iout << iINFO << "calling makeHeaps. \n";
  adjustBackgroundLoadAndComputeAverage();
  makeHeaps();
  // iout << iINFO << "Before assignment\n" << endi;
  // printLoads();

  /*
  int numOverloaded = 0;
  for (int ip=0; ip<P; ip++) {
    if ( processors[ip].backgroundLoad > averageLoad ) ++numOverloaded;
  }
  if ( numOverloaded ) {
    iout << iWARN << numOverloaded
      << " processors are overloaded due to background load.\n" << endi;
  }
  */
	      
  numAssigned = 0;

  //   for (int i=0; i<numPatches; i++)
  //     { std::cout << "(" << patches[i].Id << "," << patches[i].processor ;}
  overLoad = 1.2;
  for (int ic=0; ic<numComputes; ic++) {

    // place computes w/ patches on heavily background loaded nodes first
    // place pair before self, because self is more flexible
    c = (computeInfo *) computeBgPairHeap->deleteMax();
    if ( ! c ) c = (computeInfo *) computeBgSelfHeap->deleteMax();
    if ( ! c ) c = (computeInfo *) computePairHeap->deleteMax();
    if ( ! c ) c = (computeInfo *) computeSelfHeap->deleteMax();

    if (c->processor != -1) continue; // skip to the next compute;

    if ( ! c ) NAMD_bug("Alg7: computesHeap empty!");
    int i,j,k;
    for(i=0;i<3;i++)
      for(j=0;j<3;j++) {
        for(k=0;k<2;k++) {
	  goodP[i][j][k]=0;
	  poorP[i][j][k]=0;
        }
      }

    // first try for at least one proxy
    {
      Iterator nextProc;
      processorInfo *p;

      p = &processors[patches[c->patch1].processor];
      togrid(goodP, poorP, p, c);

      p = &processors[patches[c->patch2].processor];
      togrid(goodP, poorP, p, c);

      p = (processorInfo *)patches[c->patch1].
                            proxiesOn.iterator((Iterator *)&nextProc);
      while (p) {
        togrid(goodP, poorP, p, c);
        p = (processorInfo *)patches[c->patch1].
                            proxiesOn.next((Iterator*)&nextProc);
      }

      p = (processorInfo *)patches[c->patch2].
                            proxiesOn.iterator((Iterator *)&nextProc);
      while (p) {
        togrid(goodP, poorP, p, c);
        p = (processorInfo *)patches[c->patch2].
                            proxiesOn.next((Iterator*)&nextProc);
      }
      p = 0;
      // prefer to place compute with existing proxies over home patches
      if ((p = goodP[0][2][0])    // No home, two proxies
       || (p = goodP[1][1][0])    // One home, one proxy
       || (p = goodP[2][0][0])    // Two home, no proxies
       || (p = goodP[0][1][0])    // No home, one proxy
       || (p = goodP[1][0][0])    // One home, no proxies
       || (p = goodP[0][0][0])    // No home, no proxies
       || (p = goodP[0][1][1])    // No home, one proxy
       || (p = goodP[1][0][1])    // One home, no proxies
       || (p = goodP[0][0][1])    // No home, no proxies
         ) {
        assign(c,p); numAssigned++;
        continue;
      }
    }

    // no luck, do it the long way

    heapIterator nextProcessor;
    processorInfo *p = (processorInfo *) 
      pes->iterator((heapIterator *) &nextProcessor);
    while (p) {
      togrid(goodP, poorP, p, c);
      p = (processorInfo *) pes->next(&nextProcessor);
    }

    //    if (numAssigned >= 0) {  Else is commented out below

    p = 0;
      // prefer to place compute with existing proxies over home patches
      if ((p = goodP[0][2][0])    // No home, two proxies
       || (p = goodP[1][1][0])    // One home, one proxy
       || (p = goodP[2][0][0])    // Two home, no proxies
       || (p = goodP[0][1][0])    // No home, one proxy
       || (p = goodP[1][0][0])    // One home, no proxies
       || (p = goodP[0][0][0])    // No home, no proxies
       || (p = goodP[0][1][1])    // No home, one proxy
       || (p = goodP[1][0][1])    // One home, no proxies
       || (p = goodP[0][0][1])    // No home, no proxies
       ) {
      assign(c,p); numAssigned++;
   } else if (   // overloaded processors
          (p = poorP[0][2][0])    // No home, two proxies
       || (p = poorP[1][1][0])    // One home, one proxy
       || (p = poorP[2][0][0])    // Two home, no proxies
       || (p = poorP[0][1][0])    // No home, one proxy
       || (p = poorP[1][0][0])    // One home, no proxies
       || (p = poorP[0][0][0])    // No home, no proxies
       || (p = poorP[0][1][1])    // No home, one proxy
       || (p = poorP[1][0][1])    // One home, no proxies
       || (p = poorP[0][0][1])    // No home, no proxies
       ) {
      //iout << iWARN << "overload assign to " << p->Id << "\n" << endi;
      assign(c,p); numAssigned++;
    } else {
      NAMD_bug("*** Alg 7 No receiver found 1 ***");
      break;
    }
  }

  printLoads();

  if ( computeMax() <= origMaxLoad ) {
    // binary-search refinement procedure
    multirefine(1.05);
    printLoads();
  }

}