Skip to content

Commit

Permalink
add option "Save Minimum Spanning Tree" in Skater/Redcap
Browse files Browse the repository at this point in the history
Default "Save Spanning Tree" in Skater/Redcap removes all cuts
  • Loading branch information
lixun910 committed May 16, 2019
1 parent aa6a05e commit ea2fb90
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
31 changes: 26 additions & 5 deletions DialogTools/RedcapDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,18 @@ void RedcapDlg::CreateControls()
wxStaticText* st3 = new wxStaticText (panel, wxID_ANY, _("Save Cluster in Field:"),
wxDefaultPosition, wxDefaultSize);
m_textbox = new wxTextCtrl(panel, wxID_ANY, "CL", wxDefaultPosition, wxSize(158,-1));
chk_save_mst = new wxCheckBox(panel, wxID_ANY, "Save Minimum Spanning Tree");

wxFlexGridSizer* gbox_out = new wxFlexGridSizer(2,2,5,0);
gbox_out->Add(st3, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 10);
gbox_out->Add(m_textbox, 1, wxEXPAND);
gbox_out->Add(new wxStaticText(panel, wxID_ANY, _("(Optional)")),
0, wxALIGN_RIGHT | wxRIGHT | wxLEFT, 10);
gbox_out->Add(chk_save_mst, 1, wxEXPAND);

wxStaticBoxSizer *hbox1 = new wxStaticBoxSizer(wxHORIZONTAL, panel, _("Output:"));
hbox1->Add(st3, 0, wxALIGN_CENTER_VERTICAL);
hbox1->Add(m_textbox, 1, wxALIGN_CENTER_VERTICAL |wxLEFT, 10);


hbox1->Add(gbox_out, 1, wxEXPAND);

// Buttons
wxButton *okButton = new wxButton(panel, wxID_OK, _("Run"), wxDefaultPosition,
wxSize(70, 30));
Expand Down Expand Up @@ -425,11 +432,25 @@ void RedcapDlg::OnSaveTree(wxCommandEvent& event )
header << "0 " << project->GetNumRecords() << " ";
header << "\"" << project->GetProjectTitle() << "\" ";
header << id;


vector<vector<int> > cluster_ids = redcap->GetRegions();
map<int, int> nid_cid; // node id -> cluster id
for (int c=0; c<cluster_ids.size(); ++c) {
for (int i=0; i<cluster_ids[c].size(); ++i) {
nid_cid[ cluster_ids[c][i] ] = c;
}
}

for (int i=0; i<redcap->ordered_edges.size(); i++) {
wxString line;
int from_idx = redcap->ordered_edges[i]->orig->id;
int to_idx = redcap->ordered_edges[i]->dest->id;

if (chk_save_mst->GetValue() == false) {
if (nid_cid[from_idx] != nid_cid[to_idx])
continue;
}

double cost = redcap->ordered_edges[i]->length;
wxString line1;
line1 << ids[from_idx] << " " << ids[to_idx] << " " << cost;
Expand Down
2 changes: 2 additions & 0 deletions DialogTools/RedcapDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class RedcapDlg : public AbstractClusterDlg

wxButton* seedButton;
wxButton* saveButton;

wxCheckBox* chk_save_mst;

SpanningTreeClustering::AbstractClusterFactory* redcap;
GeoDaWeight* weights;
Expand Down
24 changes: 17 additions & 7 deletions DialogTools/SkaterDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,20 @@ void SkaterDlg::CreateControls()
hbox->Add(gbox, 1, wxEXPAND);

// Output
wxStaticText* st3 = new wxStaticText (panel, wxID_ANY, _("Save Cluster in Field:"),
wxFlexGridSizer* gbox_out = new wxFlexGridSizer(2,2,5,0);
wxStaticText* st3 = new wxStaticText(panel, wxID_ANY, _("Save Cluster in Field:"),
wxDefaultPosition, wxDefaultSize);
m_textbox = new wxTextCtrl(panel, wxID_ANY, "CL", wxDefaultPosition, wxSize(158,-1));
gbox_out->Add(st3, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 10);
gbox_out->Add(m_textbox, 1, wxEXPAND);
chk_save_mst = new wxCheckBox(panel, wxID_ANY, "Save Minimum Spanning Tree");
gbox_out->Add(new wxStaticText(panel, wxID_ANY, _("(Optional)")),
0, wxALIGN_RIGHT | wxRIGHT | wxLEFT, 10);
gbox_out->Add(chk_save_mst, 1, wxEXPAND);

wxStaticBoxSizer *hbox1 = new wxStaticBoxSizer(wxHORIZONTAL, panel, _("Output:"));
//wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL);
hbox1->Add(st3, 0, wxALIGN_CENTER_VERTICAL);
hbox1->Add(m_textbox, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);

hbox1->Add(gbox_out, 1, wxEXPAND);

// Buttons
wxButton *okButton = new wxButton(panel, wxID_OK, _("Run"), wxDefaultPosition,
wxSize(70, 30));
Expand All @@ -170,7 +176,7 @@ void SkaterDlg::CreateControls()
vbox->Add(hbox, 0, wxALIGN_CENTER | wxALL, 10);
vbox->Add(hbox1, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
vbox->Add(hbox2, 0, wxALIGN_CENTER | wxALL, 10);

// Summary control
wxBoxSizer *vbox1 = new wxBoxSizer(wxVERTICAL);
wxNotebook* notebook = AddSimpleReportCtrls(panel);
Expand Down Expand Up @@ -277,7 +283,11 @@ void SkaterDlg::OnSaveTree(wxCommandEvent& event )
for (int i=0; i<skater->ordered_edges.size(); i++) {
int from_idx = skater->ordered_edges[i]->orig->id;
int to_idx = skater->ordered_edges[i]->dest->id;
if (nid_cid[from_idx] != nid_cid[to_idx]) continue;

if (chk_save_mst->GetValue() == false) {
if (nid_cid[from_idx] != nid_cid[to_idx])
continue;
}

double cost = skater->ordered_edges[i]->length;
wxString line1;
Expand Down
2 changes: 2 additions & 0 deletions DialogTools/SkaterDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class SkaterDlg : public AbstractClusterDlg

wxButton* seedButton;
wxButton* saveButton;

wxCheckBox* chk_save_mst;

SpanningTreeClustering::Skater* skater;

Expand Down

0 comments on commit ea2fb90

Please sign in to comment.