Example #1
0
void ViewItemSet::findItemSet(ItemSet &its,bool reb){
	if(reb)
		this->reBuildTree(its);
	getLeave(getGlMainWidget()->getGraph(),leave);
	Graph *graph=getGlMainWidget()->getGraph();
	BooleanProperty *select = graph->getLocalProperty<BooleanProperty>("viewSelection");
	DoubleProperty *frequent = graph->getLocalProperty<DoubleProperty>("viewFrequent");
    vector<node> temp;
    vector<edge> path;
    double fr=0.0;
  	graph->holdObservers();
	select->setAllNodeValue(false);
	select->setAllEdgeValue(false);
	 fr=0;
	for(int i=0;i<this->leave.size();i++){
    	if(checkItemSet(leave[i],temp,path,its)){
			for(int j=0;j<temp.size();j++)
    	         select->setNodeValue(temp[j],true);

			for(int k=0;k<path.size();k++)
			     select->setEdgeValue(path[k],true);

			fr=fr+frequent->getNodeValue(leave[i]);
		   }

		  temp.clear();
          path.clear();
	}

	emit freqItemSet(fr);
    leave.clear();
	graph->unholdObservers();
}
Example #2
0
// That function sets some visual properties on a complete tree whose depth equals 5
void setTreeVisualProperties(Graph *tree) {

  // First compute a layout, we use the Bubble Tree algorithm
  LayoutProperty *viewLayout = tree->getProperty<LayoutProperty>("viewLayout");
  std::string errMsg;
  tree->applyPropertyAlgorithm("Bubble Tree", viewLayout, errMsg);

  // Then apply Auto Sizing on the nodes
  SizeProperty *viewSize = tree->getProperty<SizeProperty>("viewSize");
  tree->applyPropertyAlgorithm("Auto Sizing", viewSize, errMsg);

  // Labels the node with their id
  StringProperty *viewLabel = tree->getProperty<StringProperty>("viewLabel");
  for (auto n : tree->nodes()) {
    viewLabel->setNodeValue(n, QStringToTlpString(QString::number(n.id)));
  }

  // Add a border to the nodes, keep the default color who is black
  DoubleProperty *viewBorderWidth = tree->getProperty<DoubleProperty>("viewBorderWidth");
  viewBorderWidth->setAllNodeValue(1);

  // Build some maps to set shapes and colors according to the dag level of a node
  std::vector<int> glyphsMap;
  glyphsMap.push_back(tlp::NodeShape::Square);
  glyphsMap.push_back(tlp::NodeShape::Circle);
  glyphsMap.push_back(tlp::NodeShape::RoundedBox);
  glyphsMap.push_back(tlp::NodeShape::Hexagon);
  glyphsMap.push_back(tlp::NodeShape::Star);
  glyphsMap.push_back(tlp::NodeShape::Ring);

  std::vector<Color> colorsMap;
  colorsMap.push_back(Color::Red);
  colorsMap.push_back(Color::Azure);
  colorsMap.push_back(Color::Lemon);
  colorsMap.push_back(Color::SpringGreen);
  colorsMap.push_back(Color::Apricot);
  colorsMap.push_back(Color::Magenta);

  // Compute the Dag Level metric, the value of each node will correspond
  // to their layer id in the tree
  DoubleProperty dagLevel(tree);
  tree->applyPropertyAlgorithm("Dag Level", &dagLevel, errMsg);

  // Sets different shapes and colors for each layer of the tree
  IntegerProperty *viewShape = tree->getProperty<IntegerProperty>("viewShape");
  ColorProperty *viewColor = tree->getProperty<ColorProperty>("viewColor");
  for (auto n : tree->nodes()) {
    viewShape->setNodeValue(n, glyphsMap[int(dagLevel.getNodeValue(n))]);
    viewColor->setNodeValue(n, colorsMap[int(dagLevel.getNodeValue(n))]);
  }
}
Example #3
0
//==================================================================
bool DegreeMetric::check(std::string &errorMsg) {
  // check weights validity if it exists
  DoubleProperty *weights = nullptr;

  if (dataSet != nullptr) {
    dataSet->get("metric", weights);

    if (weights && !weights->getEdgeDefaultValue() && !weights->hasNonDefaultValuatedEdges()) {
      errorMsg = "Cannot compute a weighted degree with a null weight value\nfor all edges";
      return false;
    }
  }

  return true;
}
void TestPropertiesMinMaxAfterAddNode::testDoublePropertyMinMaxAfterAddNode() {
  DoubleProperty *doubleProp = graph->getProperty<DoubleProperty>("doubleProp");

  // add two nodes
  node n1 = graph->addNode();
  node n2 = graph->addNode();

  const double d1 = 3.5;
  const double d2 = 89.6;

  // set values to doubleProp
  doubleProp->setNodeValue(n1, d1);
  doubleProp->setNodeValue(n2, d2);
  CPPUNIT_ASSERT_EQUAL(d1, doubleProp->getNodeMin(graph));
  CPPUNIT_ASSERT_EQUAL(d2, doubleProp->getNodeMax(graph));

  // add a new node, the value associated to doubleProp property is the default one 0
  graph->addNode();

  // min should be 0
  CPPUNIT_ASSERT_EQUAL(0.0, doubleProp->getNodeMin(graph));
  CPPUNIT_ASSERT_EQUAL(d2, doubleProp->getNodeMax(graph));
}
Example #5
0
int main(int, char **) {

  /*
   * Let's create the following graph
   *
   *      A
   *    /   \
   *  B       C
   *   \     /
   *    D - E
   */

  /*
   Initialize the library and load all plugins
   */
  tlp::initTulipLib();
  PluginLoaderTxt loadertxt;
  PluginLibraryLoader::loadPlugins(&loadertxt);

  // create a new graph
  Graph *myGraph = tlp::newGraph();

  node a = myGraph->addNode();
  node b = myGraph->addNode();
  node c = myGraph->addNode();
  node d = myGraph->addNode();
  node e = myGraph->addNode();

  myGraph->addEdge(a, b);
  myGraph->addEdge(a, c);
  myGraph->addEdge(b, d);
  myGraph->addEdge(c, e);
  myGraph->addEdge(d, e);

  // now in color. 'viewColor' is the Tulip GUI's default color property, so when we load it we will
  // see the color immediately
  // If 'viewColor' did not exist before, this creates it.
  ColorProperty *color = myGraph->getProperty<ColorProperty>("viewColor");
  color->setNodeValue(a, Color(255, 0, 0));
  color->setNodeValue(b, Color(0, 255, 0));
  color->setNodeValue(c, Color(0, 0, 255));
  color->setNodeValue(d, Color(255, 0, 0));
  color->setNodeValue(e, Color(0, 255, 0));
  // hey look, this is a 3-coloration :)

  // set the label of the nodes (again, with Tulip's default label property)
  StringProperty *label = myGraph->getProperty<StringProperty>("viewLabel");
  label->setNodeValue(a, "A");
  label->setNodeValue(b, "B");
  label->setNodeValue(c, "C");
  label->setNodeValue(d, "D");
  label->setNodeValue(e, "E");

  DoubleProperty *metric = myGraph->getProperty<DoubleProperty>("degree");

  // if the degree plugin is available, let's call it.
  if (tlp::PluginLister::instance()->pluginExists("Degree")) {
    // now compute the degree of the nodes.
    string errorMessage;
    // this calls the Tulip plugin 'Degree'.
    bool success = myGraph->applyPropertyAlgorithm("Degree", metric, errorMessage);

    if (!success) {
      std::cout << errorMessage << std::endl;
    }
  } else {
    std::cout << "could not find the plugin, computing" << std::endl;
    for (auto n : myGraph->nodes()) {
      metric->setNodeValue(n, myGraph->deg(n));
    }
  }

  // output the degree of node a;
  std::cout << metric->getNodeValue(a) << std::endl;

  // saveGraph is a shortcut ofr exportGraph that uses the TLP export.
  tlp::saveGraph(myGraph, "mygraph.tlp");

  return EXIT_SUCCESS;
}
 bool operator() (node n1,node n2) {
   return (metric->getNodeValue(n1) < metric->getNodeValue(n2));
 }