- Timestamp:
- 08/06/08 15:32:33 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.DataAnalysis
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAnalysis/HeuristicLab.DataAnalysis.csproj
r454 r457 51 51 </ItemGroup> 52 52 <ItemGroup> 53 <Compile Include="RowShuffler.cs"> 54 <SubType>Form</SubType> 55 </Compile> 53 56 <Compile Include="DataFormatException.cs" /> 54 57 <Compile Include="Dataset.cs" /> … … 70 73 <Compile Include="Properties\AssemblyInfo.cs" /> 71 74 <Compile Include="Regression.cs" /> 72 <Compile Include="RowShuffler.cs" />73 75 <Compile Include="Statistics.cs" /> 74 76 <Compile Include="SvmExporter.cs"> … … 95 97 </ItemGroup> 96 98 <ItemGroup> 99 <EmbeddedResource Include="RowShuffler.resx"> 100 <DependentUpon>RowShuffler.cs</DependentUpon> 101 <SubType>Designer</SubType> 102 </EmbeddedResource> 97 103 <EmbeddedResource Include="DatasetView.resx"> 98 104 <DependentUpon>DatasetView.cs</DependentUpon> -
trunk/sources/HeuristicLab.DataAnalysis/RowShuffler.cs
r454 r457 24 24 using System.Linq; 25 25 using System.Text; 26 using System.Windows.Forms; 27 using System.IO; 28 using System.Globalization; 26 29 27 30 namespace HeuristicLab.DataAnalysis { 28 public class RowShuffler : IDatasetManipulator { 31 class RowShuffler : Form, IDatasetManipulator { 32 private Label helpLabel; 33 private Button nextButton; 34 private DataGridView dataGridView; 35 private Dataset dataset; 36 public RowShuffler() 37 : base() { 38 InitializeComponent(); 39 } 40 41 42 #region IDatasetManipulator Members 43 29 44 public string Action { 30 get { return "Shuffle rows "; }45 get { return "Shuffle rows..."; } 31 46 } 32 47 33 48 public void Execute(Dataset dataset) { 34 Random random = new Random(); 35 for(int i = 0; i < dataset.Rows - 1; i++) { 36 int j = random.Next(i, dataset.Rows); 37 ExchangeRows(dataset, i, j); 49 this.dataset = dataset; 50 dataGridView.ColumnCount = dataset.Columns; 51 dataGridView.RowCount = dataset.Rows; 52 for(int i = 0; i < dataset.Rows; i++) { 53 for(int j = 0; j < dataset.Columns; j++) { 54 dataGridView.Rows[i].Cells[j].Value = dataset.GetValue(i, j); 55 dataGridView.Rows[i].HeaderCell.Value = i.ToString(); 56 } 38 57 } 58 for(int i = 0; i < dataset.Columns; i++) { 59 dataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; 60 dataGridView.Columns[i].Name = dataset.VariableNames[i]; 61 } 62 dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 63 64 ShowDialog(); 39 65 } 40 66 … … 46 72 } 47 73 } 74 75 #endregion 76 77 private void InitializeComponent() { 78 System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); 79 this.dataGridView = new System.Windows.Forms.DataGridView(); 80 this.helpLabel = new System.Windows.Forms.Label(); 81 this.nextButton = new System.Windows.Forms.Button(); 82 ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); 83 this.SuspendLayout(); 84 // 85 // dataGridView 86 // 87 this.dataGridView.AllowUserToAddRows = false; 88 this.dataGridView.AllowUserToDeleteRows = false; 89 this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 90 | System.Windows.Forms.AnchorStyles.Left) 91 | System.Windows.Forms.AnchorStyles.Right))); 92 this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 93 this.dataGridView.Location = new System.Drawing.Point(12, 25); 94 this.dataGridView.Name = "dataGridView"; 95 this.dataGridView.ReadOnly = true; 96 dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; 97 dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; 98 dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 99 dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; 100 dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; 101 dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; 102 dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; 103 this.dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle1; 104 this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; 105 this.dataGridView.Size = new System.Drawing.Size(607, 444); 106 this.dataGridView.TabIndex = 0; 107 this.dataGridView.SelectionChanged += new System.EventHandler(this.dataGridView_SelectionChanged); 108 // 109 // helpLabel 110 // 111 this.helpLabel.AutoSize = true; 112 this.helpLabel.Location = new System.Drawing.Point(12, 9); 113 this.helpLabel.Name = "helpLabel"; 114 this.helpLabel.Size = new System.Drawing.Size(183, 13); 115 this.helpLabel.TabIndex = 1; 116 this.helpLabel.Text = "Please select the rows to be shuffled."; 117 // 118 // nextButton 119 // 120 this.nextButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 121 this.nextButton.Location = new System.Drawing.Point(544, 475); 122 this.nextButton.Name = "nextButton"; 123 this.nextButton.Size = new System.Drawing.Size(75, 23); 124 this.nextButton.TabIndex = 2; 125 this.nextButton.Text = "Next..."; 126 this.nextButton.UseVisualStyleBackColor = true; 127 this.nextButton.Click += new System.EventHandler(this.nextButton_Click); 128 // 129 // RowShuffler 130 // 131 this.ClientSize = new System.Drawing.Size(631, 510); 132 this.Controls.Add(this.nextButton); 133 this.Controls.Add(this.helpLabel); 134 this.Controls.Add(this.dataGridView); 135 this.Name = "RowShuffler"; 136 this.Text = "Row shuffler"; 137 ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); 138 this.ResumeLayout(false); 139 this.PerformLayout(); 140 141 } 142 143 private void dataGridView_SelectionChanged(object sender, EventArgs e) { 144 if(dataGridView.SelectedRows.Count > 1) nextButton.Enabled = true; 145 else nextButton.Enabled = false; 146 } 147 148 private void nextButton_Click(object sender, EventArgs e) { 149 Random random = new Random(); 150 for(int i = 0; i < dataGridView.SelectedRows.Count - 1; i++) { 151 int j = random.Next(i, dataGridView.SelectedRows.Count); 152 int col0 = dataGridView.SelectedRows[i].Index; 153 int col1 = dataGridView.SelectedRows[j].Index; 154 ExchangeRows(dataset, i, j); 155 } 156 157 Close(); 158 } 48 159 } 49 160 }
Note: See TracChangeset
for help on using the changeset viewer.