📄 indiscernibilitygraphexporter.cpp
字号:
//-------------------------------------------------------------------// Author........: Aleksander 豩rn// Date..........:// Description...:// Revisions.....://===================================================================#include <stdafx.h> // Precompiled headers.#include <copyright.h>#include <kernel/algorithms/indiscernibilitygraphexporter.h>#include <kernel/algorithms/keyword.h>#include <kernel/structures/decisiontable.h>#include <kernel/structures/discernibilitymatrix.h>#include <kernel/structures/indiscernibilitygraph.h>#include <kernel/utilities/creator.h>#include <kernel/utilities/discerner.h>#include <kernel/basic/message.h>#include <kernel/system/fstream.h>//-------------------------------------------------------------------// Methods for class IndiscernibilityGraphExporter.//===================================================================//-------------------------------------------------------------------// Constructors/destructor.//===================================================================IndiscernibilityGraphExporter::IndiscernibilityGraphExporter() { reflexive_ = true; deg_ = false; apsp_ = false; ignore_ = false; cardinality_ = 0;}IndiscernibilityGraphExporter::~IndiscernibilityGraphExporter() {}//-------------------------------------------------------------------// Methods inherited from Identifier.//===================================================================IMPLEMENTIDMETHODS(IndiscernibilityGraphExporter, INDISCERNIBILITYGRAPHEXPORTER, DiscernibilityExporter)//-------------------------------------------------------------------// Methods inherited from Algorithm.//===================================================================//-------------------------------------------------------------------// Method........: GetParameters// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================StringIndiscernibilityGraphExporter::GetParameters() const { String parameters = DiscernibilityExporter::GetParameters(); if (!parameters.EndsWith(Keyword::Separator())) parameters += Keyword::Separator(); // Include reflexive stuff? parameters += Keyword::Data() + Keyword::Dot() + Keyword::Reflexive(); parameters += Keyword::Assignment(); parameters += String::Format(IncludeReflexiveData()); parameters += Keyword::Separator(); // Include vertex degree data? parameters += Keyword::Data() + Keyword::Dot() + Keyword::Degree(); parameters += Keyword::Assignment(); parameters += String::Format(IncludeDegreeData()); parameters += Keyword::Separator(); // Include APSP data? parameters += Keyword::Data() + Keyword::Dot() + Keyword::APSP(); parameters += Keyword::Assignment(); parameters += String::Format(IncludeAPSPData()); parameters += Keyword::Separator(); // Ignore low-cardinality entries? parameters += Keyword::Cardinality(); parameters += Keyword::Assignment(); parameters += String::Format(IgnoreLowCardinalityEntries()); // Maximum cardinality, if relevant. if (IgnoreLowCardinalityEntries()) { parameters += Keyword::Separator(); parameters += Keyword::Cardinality() + Keyword::Dot() + Keyword::Threshold(); parameters += Keyword::Assignment(); parameters += String::Format(GetMaximumCardinality()); } return parameters;}//-------------------------------------------------------------------// Method........: SetParameter// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolIndiscernibilityGraphExporter::SetParameter(const String &keyword, const String &value) { // Reflexive data. if (keyword == Keyword::Data() + Keyword::Dot() + Keyword::Reflexive() && value.IsBoolean()) return IncludeReflexiveData(value.GetBoolean()); // Vertex degree data. if (keyword == Keyword::Data() + Keyword::Dot() + Keyword::Degree() && value.IsBoolean()) return IncludeDegreeData(value.GetBoolean()); // APSP data. if (keyword == Keyword::Data() + Keyword::Dot() + Keyword::APSP() && value.IsBoolean()) return IncludeAPSPData(value.GetBoolean()); // Ignore low-cardinality entries? if (keyword == Keyword::Cardinality() && value.IsBoolean()) return IgnoreLowCardinalityEntries(value.GetBoolean()); // Cardinality threshold. if ((keyword == Keyword::Cardinality() + Keyword::Dot() + Keyword::Threshold()) && value.IsInteger()) return SetMaximumCardinality(value.GetInteger()); return DiscernibilityExporter::SetParameter(keyword, value);}//-------------------------------------------------------------------// Methods inherited from Exporter.//===================================================================//-------------------------------------------------------------------// Method........: ExportPrologue// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......: Overloaded since we want the prologue in GraphViz// comment format.// Revisions.....://===================================================================boolIndiscernibilityGraphExporter::ExportPrologue(ofstream &stream, const Structure &structure) const { stream << "/* ===========================================================" << endl; stream << "Output from ROSETTA, " + SystemKit::GetUser() + " " + SystemKit::GetTimestamp() << endl; stream << endl; stream << IdHolder::GetClassname(GetId()) << endl; stream << '{' << GetParameters() << '}' << endl; stream << endl; stream << structure.GetName() << endl; stream << endl; stream << "This graph can be visualized by GraphViz from AT&T Research." << endl; stream << "=========================================================== */" << endl; stream << endl; return true;}//-------------------------------------------------------------------// Methods inherited from DiscernibilityExporter.//===================================================================//-------------------------------------------------------------------// Method........: ExportData// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......: Creating a graph from a full matrix is really// only suitable for not too large datasets.// Resolve later.// Revisions.....://===================================================================boolIndiscernibilityGraphExporter::ExportData(ofstream &stream, const Discerner &discerner, const DecisionTable &table, bool masked, int name_index_unmasked) const { DiscernibilityMatrix matrix; IndiscernibilityGraph graph; Message message; message.Notify("Creating indiscernibility graph..."); float precision = Undefined::Float(); int cardinality = IgnoreLowCardinalityEntries() ? GetMaximumCardinality() : 0; // Create it... if (ModuloDecision()) { if (!matrix.Create(table, masked, true, discerner, precision) || !graph.Create(matrix, cardinality)) return false; } else { if (!graph.Create(table, masked, discerner, true, cardinality, name_index_unmasked)) return false; } graph.SetName("indiscernibility"); // ...and export it. return ExportGraph(stream, graph, table, masked);}//-------------------------------------------------------------------// New methods.//===================================================================//-------------------------------------------------------------------// Method........: ExportGraph// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......: Called from the ExportData method//.// Graph::GetAttribute() should return the index// (unmasked) of the attribute in the given table that// specifies the names of the nodes in the graph, if// such an attribute was given by the user.//// The graph is assumed to be symmetric.//// Revisions.....: A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -