20 #include "ui_TransformEdgesWidget.h"
27 #include <QtGui/QDesktopWidget>
28 #include <QtGui/QGridLayout>
29 #include <QtGui/QLabel>
30 #include <QtGui/QLineEdit>
31 #include <QtGui/QPushButton>
32 #include <QtGui/QSpinBox>
33 #include <QtCore/QMap>
34 #include <QtCore/QPair>
36 #include <boost/graph/adjacency_list.hpp>
37 #include <boost/graph/topology.hpp>
40 #include <DataStructure.h>
41 #include <DocumentManager.h>
42 #include "../DataStructures/Graph/GraphStructure.h"
57 ui =
new Ui::TransformEdgesWidget;
59 setMainWidget(widget);
62 setCaption(i18nc(
"@title:window",
"Transform Edges"));
63 setButtons(KDialog::Cancel | KDialog::Ok);
64 KDialog::centerOnScreen(widget, -3);
78 ui->dataStructuresCombo->insertItems(0, dsNames);
84 DataStructurePtr graph;
88 if (ui->dataStructuresCombo->count() == 0)
91 graph = dsList[ui->dataStructuresCombo->currentIndex()];
95 if (ui->radioButtonMakeComplete->isChecked())
97 if (ui->radioButtonEraseEdges->isChecked())
98 removeAllEdges(graph);
99 if (ui->radioButtonReverseEdges->isChecked())
100 reverseAllEdges(graph);
101 if (ui->radioButtonMakeSpanningtree->isChecked())
102 makeSpanningTree(graph);
106 void TransformEdgesWidget::makeComplete(DataStructurePtr graph)
108 bool directed = graph->document()->pointerType(0)->direction() == PointerType::Unidirectional;
111 foreach(PointerPtr e, graph->pointers(0)) {
115 int size_i = graph->dataList(0).size() - 1;
116 for (
int i = 0; i < size_i; ++i) {
117 for (
int e = i + 1; e < graph->dataList(0).size(); ++e) {
118 graph->createPointer(graph->dataList(0).at(i), graph->dataList(0).at(e), 0);
120 graph->createPointer(graph->dataList(0).at(e), graph->dataList(0).at(i), 0);
127 void TransformEdgesWidget::removeAllEdges(DataStructurePtr graph)
131 foreach(PointerPtr e, graph->pointers(0)) {
138 void TransformEdgesWidget::reverseAllEdges(DataStructurePtr graph)
140 foreach(
int typeId, graph->document()->pointerTypeList()) {
141 if (graph->document()->pointerType(typeId)->direction() == PointerType::Bidirectional) {
145 foreach(PointerPtr e, graph->pointers(typeId)) {
146 newPointers << QPair< DataPtr, DataPtr >(e->to(), e->from());
150 for (
int i = 0; i < newPointers.
count(); i++) {
151 graph->createPointer(newPointers[i].first, newPointers[i].second, typeId);
157 qreal TransformEdgesWidget::makeSpanningTree(DataStructurePtr graph)
159 boost::shared_ptr<GraphStructure> graphDS = boost::static_pointer_cast<GraphStructure>(graph);
164 int n = vertices.
size();
177 for (
int i = 0; i < vertices.
size(); i++) {
178 distance[i] = std::numeric_limits<unsigned int>::max();
186 for (
int i = 0; i < vertices.
size(); i++) {
196 for (
int i = 0; i < n; i++) {
197 for (
int j = 0; j < n; j++) {
201 out = vertices[i]->pointerList();
203 for (
int k = 0; k < out.size(); k++) {
204 if (out[k]->to() == vertices[j]) {
225 for (
int i = 0; i < n; ++i) {
227 distance[i] = weight[QPair<int, int>(0, i)] ;
233 for (
int treeSize = 1; treeSize < n; treeSize++) {
236 for (
int i = 0; i < n; ++i) {
237 if (inTree[i] ==
false) {
238 if ((min == -1) || (distance[min] > distance[i])) {
245 MST << QPair<int, int>(successor[min], min);
247 total += distance[min];
250 for (
int i = 0; i < n; ++i) {
259 removeAllEdges(graph);
262 for (
int i = 0; i < MST.
size(); i++) {
263 PointerPtr ptr = graph->createPointer(vertices[MST[i].first], vertices[MST[i].second], 0);
268 ptr->setProperty(
"value", s);
iterator remove(iterator pos)
int count(const T &value) const
QVariant property(const char *name) const
QString & setNum(short n, int base)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)