/****************************************************************/
/* */
/* PosetImport.cpp */
/* Reads in the poset given by the matrices. */
/* Expected input is = ... */
/* Where is a positive number, */
/* and is a x 0-1 matrix. */
/* The delimeters between the numbers can be any white */
/* space. Any remaining data in the file is ignored. */
/* If there is no enough tokens to generate the graph */
/* an exception is generated. */
/* */
/* Written by Luis Garcia & Davud Auber. */
/* October, 2001 */
/* */
/****************************************************************/
#include
#include
#include
using namespace std;
struct PosetImport:public ImportModule
{
PosetImport(ClusterContext context):ImportModule(context){
addParameter("filename");
}
~PosetImport(){}
bool import(const string &name)
{
std::ifstream in(name.c_str());
unsigned int size=0;
char v;
int layerDraw=0;
LayoutProxy *posetLayout=getProxy(superGraph,"viewLayout");
getProxy(superGraph,"viewSize")->setAllNodeValue(Size(1,1,1));
in>>size;
//some error checking
if (size==0)
{
std::cerr<<"****\n**** File "< layer1, layer2, *layerup, *layerdown;
for (unsigned int i=0;iaddNode());
posetLayout->setNodeValue(layer1[i],Coord(size*2-i*2,layerDraw,0));
layer2.push_back(superGraph->addNode());
posetLayout->setNodeValue(layer2[i],Coord(size*2-i*2,layerDraw+1,0));
}
layerDraw++;
// StringProxy *labels=getLocalProxy(superGraph->getPropertyProxyContainer(),"viewLabel");
//create edges
layerup = &layer1;
layerdown =&layer2;
do
{
for (unsigned int i=0;i>v;
if (v=='1')
superGraph->addEdge((*layerup)[i],(*layerdown)[j]);
}
}
in>>v;
if(v=='+')
{
//Build a new layer
{
layerup->clear();
for (unsigned int i=0;ipush_back(superGraph->addNode());
posetLayout->setNodeValue((*layerup)[i],Coord(size*2-i*2,layerDraw+1,0));
}
layerDraw++;
}
//Swap the two layers
{
vector *tmp=layerup;
layerup=layerdown;
layerdown=tmp;
}
}
}while (v=='+');
return true;
}
};
IMPORTPLUGIN(PosetImport,"Poset Import","Luis & David", "10/31/2001","0","0","1")