コード例 #1
0
ファイル: Filler.cpp プロジェクト: DATX02-16-86/Code
static void relaxPoints(FillContext& context, Size iterations) {
    auto chunkSize = context.chunkSize;
    auto cx = context.chunkX;
    auto cy = context.chunkY;
    auto& points = context.points;

    for(int i = 0; i < iterations; ++i) {
        Diagram diagram;
        construct_voronoi(points.begin(), points.end(), &diagram);

        for(const DiagramCell& it : diagram.cells()) {
            auto edge = it.incident_edge();
            CoordinateType x = 0;
            CoordinateType y = 0;
            int count = 0;
            do {
                edge = edge->next();
                auto edgePoints = getEdgePoints(*edge, points);
                x += edgePoints.first.x() - cx * chunkSize;
                y += edgePoints.first.y() - cy * chunkSize;
                ++count;
            } while (edge != it.incident_edge());
            points[it.source_index()].x(x / count + cx * chunkSize);
            points[it.source_index()].y(y / count + cy * chunkSize);
        }
    }
}
コード例 #2
0
ファイル: Ted.cpp プロジェクト: spadidar/theorem_prover
int main()
{
  cout << "* Euler Diagram Theorem Prover *\n" << endl;
  
  Ted ted;
  DiagramHolder holder;

  string command = "";
  
  while( command != "exit") 
    {
      cout << "Enter Command (help for help): " ;
      cin >> command;

      //Help-------------------------------
      if (command == "help")
	{
	  cout << "Commands are: \n" << endl;
	  
	  cout << " -l   = Load Diagram \n" << endl;
	  cout << " -p   = Prove Diagrams \n" << endl;
	  cout << " -c   = Clear Prover \n" << endl;
	  cout << " -dor = Apply Demorgan Or \n" <<endl;
	  cout << " -dand = Apply Demorgan And \n" <<endl;
	  cout << "\n" ;

	  cout << " exit = Quits the program \n" << endl;
	}
      
      //Load Diagram
	  
      else if(command == "-l")
	{
	  string dName = "";
	  cout << "Diagram File  Name: " ;

	  cin >> dName;

	  if (dName != "")
	    {
	      Diagram d = ted.getDiagram( dName);//load diagram
	      if(d.getLabel() == "EMPT")
		cout << "Error! Loading Diagram Failed" << endl;
	      else
		{
		  Rules rules(d);
		  d = rules.returnCurrentDiagram();
	      
		  holder.addDiagram(d);//save it
		}
	    }
	  else
	    cout << "File name error!" << endl;

	}

      //Prover--------------------------------
      else if( command == "-p")
コード例 #3
0
void CompoundNodeTest::setLeftTest()
{
  Diagram d1("d1");
  Diagram d2("d2");
  Diagram d("empty");

  CompoundNode *p = new CompoundNode("root");
  CompoundNode *a = new CompoundNode(d1,"leaf");
  CompoundNode *b = new CompoundNode(d2,"leaf");
  
  Diagram dd = a->getPayload();
  cout << "Diagram is : " << dd.getLabel() << endl;
}
コード例 #4
0
 void ProjectComponent::handleProjectFileOpened(const AutoPtr<ProjectFileOpened>& notification)
 {
     FileController& controller = FileController::get();
     Project* project = controller.getProject();
     _tabs->clearTabs();
     Diagram* diagram = NULL;
     project->beginIteration();
     while (diagram = project->getNextChild())
     {
         if (diagram->get<string>("class") == string("usecase"))
         {
             UseCaseDiagram* usecaseDiagram = addUseCaseDiagram(diagram->getName());
             usecaseDiagram->populateFrom(diagram);
         }
     }
     _tabs->setCurrentTabIndex(0);
 }
コード例 #5
0
ファイル: ProjectTest.cpp プロジェクト: akosma/remproject
    void ProjectTest::testCanAddElementsUsingOperator()
    {
        string first("first");
        string second("second");
        string diagramClassName("usecase");

        Project project;
        Diagram* firstDiagram = new Diagram(diagramClassName);
        firstDiagram->setName(first);
        Diagram* secondDiagram = new Diagram(diagramClassName);
        secondDiagram->setName(second);
        
        project << firstDiagram << secondDiagram;
        CPPUNIT_ASSERT_EQUAL(2, project.getChildrenCount());
        
        delete firstDiagram;
        delete secondDiagram;
    }
コード例 #6
0
ファイル: Prover.cpp プロジェクト: spadidar/theorem_prover
/*
 *compare all zones with selected zones
 *get the missings
 *add them as shaded zone
 *reset selected zones to all zones
 */
Diagram Prover::addMissingZones(Diagram d)
{
  Rules rules(d);

  vector<Zone> selectedZones = d.getSelectedZones();
  vector<Zone> allZones = d.getAllZones();
  vector<Zone> shz = d.getShadedZones();
  vector<Zone> missings;
  vector<Zone> newSelectedZ;
  vector<Zone> newSZ;

 
  for (int i =0; i< allZones.size() ; i++)
    {
      bool found = false;

      for (int j= 0; j < selectedZones.size() ; j++)
	{
	  if(allZones[i].equals(selectedZones[j]))
	    {
	      found = true;
	    }  
	}

      //copy to missings vec
      if( found == false)
	missings.push_back(allZones[i]);

    }

  //add missing shaded zones using the rule

  for(int i = 0; i< missings.size(); i ++)
    holder.addDiagram(rules.addShadedZone(missings[i]));     

  //returning the final diagram that has all the correct zones/sz
  if(missings.size() > 0)
    {

      Diagram final = holder.getLastDiagram();

      return final;
 
    }
コード例 #7
0
ファイル: ProjectTest.cpp プロジェクト: akosma/remproject
    void ProjectTest::testCanRetrieveElementsUsingOperator()
    {
        string first("first");
        string second("second");
        string diagramClassName("usecase");

        Project project;
        Diagram* firstDiagram = new Diagram(diagramClassName);
        firstDiagram->setName(first);
        Diagram* secondDiagram = new Diagram(diagramClassName);
        secondDiagram->setName(second);
        
        project << firstDiagram << secondDiagram;
        
        Diagram* pointer = project[first];
        CPPUNIT_ASSERT(pointer);
        CPPUNIT_ASSERT_EQUAL((int)pointer, (int)firstDiagram);
        
        delete firstDiagram;
        delete secondDiagram;
    }
コード例 #8
0
ファイル: ProjectTest.cpp プロジェクト: akosma/remproject
    void ProjectTest::testCanRemoveAllDiagramsFromProject()
    {
        string first("first");
        string second("second");
        string diagramClassName("usecase");

        Project project;
        CPPUNIT_ASSERT(!project.hasChildren());
        
        Diagram* firstDiagram = new Diagram(diagramClassName);
        firstDiagram->setName(first);
        
        project.addChild(firstDiagram);
        CPPUNIT_ASSERT_EQUAL(1, project.getChildrenCount());
        
        Diagram* pointer = project.getChild(first);
        CPPUNIT_ASSERT_EQUAL((int)firstDiagram, (int)pointer);
        CPPUNIT_ASSERT_EQUAL(first, pointer->getName());

        Diagram* secondDiagram = new Diagram(diagramClassName);
        secondDiagram->setName(second);
        
        project.addChild(secondDiagram);
        CPPUNIT_ASSERT_EQUAL(2, project.getChildrenCount());

        project.removeAllChildren();
        CPPUNIT_ASSERT_EQUAL(0, project.getChildrenCount());

        // Do not do the following:
        // delete firstDiagram;
        // delete secondDiagram;
        // This is because "project" owns the diagrams and will delete them
        // when the stack is cleared, at the end of this method.
    }
コード例 #9
0
void VoronoiDiagram::updateEdges(const Diagram& diagram) {
    //LOG << "Boost voronoi has " << diagram.cells().size() << " cells\n";
    for (auto& cell : diagram.cells()) {
        assert(cell.contains_point()); // Cell should be created by point seed
        const voronoi_diagram<Real>::edge_type* edge = cell.incident_edge();
        assert(edge->is_linear()); // For points all edges should be linear
        assert(edge != nullptr);
        cells.emplace_back(seeds.at(cell.source_index()), diagramLiftOnZ);
        auto& lastCell = cells.at(cells.size() - 1);
        do {
            if (edge->is_primary()) {
                auto voronoiEdge = ToVoronoiEdge(*edge);
                try {
                    voronoiEdge = getRayBoundedToArena(voronoiEdge);
                    lastCell.addEdge(move(voronoiEdge));
                }
                catch(EdgeNotInArea& e) {
                    // Do not add this edge
                }
            }
            edge = edge->next();
        } while (edge != cell.incident_edge());
    }
}
コード例 #10
0
RealType
wasserstein_distance(const Diagram& dgm1, const Diagram& dgm2, int p)
{
    typedef         RealType                    Distance;
    typedef         typename Diagram::Point     Point;
    typedef         Linfty<Point, Point>        Norm;

    unsigned size = dgm1.size() + dgm2.size();
    Norm norm;

    // Setup the matrix
    Matrix<Distance>        m(size,size);
    for (unsigned i = 0; i < dgm1.size(); ++i)
        for (unsigned j = 0; j < dgm2.size(); ++j)
        {
            const Point& p1 = *(dgm1.begin() + i);
            const Point& p2 = *(dgm2.begin() + j);
            m(i,j) = pow(norm(p1, p2),  p);
            m(j + dgm1.size(), i + dgm2.size()) = 0;
        }

    for (unsigned i = 0; i < dgm1.size(); ++i)
        for (unsigned j = dgm2.size(); j < size; ++j)
        {
            const Point& p1 = *(dgm1.begin() + i);
            m(i,j) = pow(norm.diagonal(p1), p);
        }

    for (unsigned j = 0; j < dgm2.size(); ++j)
        for (unsigned i = dgm1.size(); i < size; ++i)
        {
            const Point& p2 = *(dgm2.begin() + j);
            m(i,j) = pow(norm.diagonal(p2), p);
        }

    // Compute weighted matching
    Munkres munkres;
    munkres.solve(m);

    // Assume everything is assigned (i.e., that we have a perfect matching)
    Distance sum = 0;
    for (unsigned i = 0; i < size; i++)
        for (unsigned j = 0; j < size; j++)
            if (m(i,j) == 0)
            {
                //std::cout << i << ": " << j << '\n';
                //sum += m[i][j];
                if (i >= dgm1.size())
                {
                    if (j >= dgm2.size())
                        sum += 0;
                    else
                    {
                        const Point& p2 = *(dgm2.begin() + j);
                        sum += pow(norm.diagonal(p2), p);
                    }
                } else
                {
                    if (j >= dgm2.size())
                    {
                        const Point& p1 = *(dgm1.begin() + i);
                        sum += pow(norm.diagonal(p1), p);
                    } else
                    {
                        const Point& p1 = *(dgm1.begin() + i);
                        const Point& p2 = *(dgm2.begin() + j);
                        sum += pow(norm(p1, p2),  p);
                    }
                }
                break;
            }

    return sum;
}
コード例 #11
0
ファイル: sweepdialog.cpp プロジェクト: mdavidsaver/qucs
// ---------------------------------------------------
Graph* SweepDialog::setBiasPoints()
{
  // When this function is entered, a simulation was performed.
  // Thus, the node names are still in "node->Name".

  bool hasNoComp;
  Graph *pg = new Graph("");
  Diagram *Diag = new Diagram();
  QFileInfo Info(Doc->DocName);
  QString DataSet = Info.dirPath() + QDir::separator() + Doc->DataSet;

  Node *pn;
  Element *pe;
  // create DC voltage for all nodes
  for(pn = Doc->Nodes->first(); pn != 0; pn = Doc->Nodes->next()) {
    if(pn->Name.isEmpty()) continue;

    pn->x1 = 0;
    if(pn->Connections.count() < 2) {
      pn->Name = "";  // no text at open nodes
      continue;
    }
    else {
      hasNoComp = true;
      for(pe = pn->Connections.first(); pe!=0; pe = pn->Connections.next())
        if(pe->Type == isWire) {
          if( ((Wire*)pe)->isHorizontal() )  pn->x1 |= 2;
        }
        else {
          if( ((Component*)pe)->Model == "GND" ) {
            hasNoComp = true;   // no text at ground symbol
            break;
          }

          if(pn->cx < pe->cx)  pn->x1 |= 1;  // to the right is no room
          hasNoComp = false;
        }
      if(hasNoComp) {  // text only were a component is connected
        pn->Name = "";
        continue;
      }
    }

    pg->Var = pn->Name + ".V";
    if(Diag->loadVarData(DataSet, pg)) {
      pn->Name = num2str(*(pg->cPointsY)) + "V";
      NodeList.append(pn);             // remember node ...
      ValueList.append(pg->cPointsY);  // ... and all of its values
      pg->cPointsY = 0;   // do not delete it next time !
    }
    else
      pn->Name = "0V";


    for(pe = pn->Connections.first(); pe!=0; pe = pn->Connections.next())
      if(pe->Type == isWire) {
        if( ((Wire*)pe)->Port1 != pn )  // no text at next node
          ((Wire*)pe)->Port1->Name = "";
        else  ((Wire*)pe)->Port2->Name = "";
      }
  }


  // create DC current through each probe
  Component *pc;
  for(pc = Doc->Components->first(); pc != 0; pc = Doc->Components->next())
    if(pc->Model == "IProbe") {
      pn = pc->Ports.first()->Connection;
      if(!pn->Name.isEmpty())   // preserve node voltage ?
        pn = pc->Ports.at(1)->Connection;

      pn->x1 = 0x10;   // mark current
      pg->Var = pc->Name + ".I";
      if(Diag->loadVarData(DataSet, pg)) {
        pn->Name = num2str(*(pg->cPointsY)) + "A";
        NodeList.append(pn);             // remember node ...
        ValueList.append(pg->cPointsY);  // ... and all of its values
        pg->cPointsY = 0;   // do not delete it next time !
      }
      else
        pn->Name = "0A";

      for(pe = pn->Connections.first(); pe!=0; pe = pn->Connections.next())
        if(pe->Type == isWire) {
          if( ((Wire*)pe)->isHorizontal() )  pn->x1 |= 2;
        }
        else {
          if(pn->cx < pe->cx)  pn->x1 |= 1;  // to the right is no room
        }
    }


  Doc->showBias = 1;
  delete Diag;
  return pg;
}
コード例 #12
0
ファイル: Prover.cpp プロジェクト: spadidar/theorem_prover
bool Prover::prove(Diagram d1, Diagram d2)
{
  Diagram premise("p");
  Diagram conclusion("c");
  Diagram marker("EMPTY"); //marker for printing	
  Diagram localConc("c");
  Diagram localPre("p");

  premise =  d1;
  localPre = d1;

  conclusion = d2;
  localConc = d2; //holding conc for adding later
	
  holder.addDiagram(premise);
  
  //**************************************************

  Diagram afterPSZ = addMissingZones(premise);
  premise = afterPSZ; //update premise to new premise 
  
  Diagram afterPMC = addMissingContours(premise, conclusion);

  holder.addDiagram(marker);	

  Diagram afterCMZ = addMissingZones(conclusion);
  conclusion = afterCMZ; //update conclusion to new conclusion

  Diagram afterCMC = addMissingContours(conclusion, premise );

  //***************************************************

  holder.addDiagram(localConc);
  

  holder.displayAllDiagrams();

  vector<Zone> finalPSZ = afterPMC.getShadedZones(); // get shaded z of
  // last premise and
  // last conclusion
  vector<Zone> finalCSZ = afterCMC.getShadedZones();


//   for (int i =0; i< finalCSZ.size() ; i++)
//     {
//       cout << "zone in Conclusion :" << finalCSZ[i].getPair()<< endl;
//     }
//  for(int j =0; j< finalPSZ.size() ; j++)
//    {
//      cout << "zone in premise :" << finalPSZ[j].getPair()<< endl;
//    }
  vector<int> inds; // index holder

  //if final shaded zs of conclusion is a subset of the zones there is
  //a proof
  for (int i =0; i< finalCSZ.size() ; i++)
    {
      for(int j =0; j< finalPSZ.size() ; j++)
	{
	  if( finalCSZ[i].equals(finalPSZ[j]) )
	    {
	      inds.push_back(i);
	    }
	}
    }
  
  if(inds.size() == finalCSZ.size())
    return true;
  
  return false;
}