private void btnMetisData_Click(object sender, EventArgs e) { //��level2������תΪmetis�ܹ�����Ĵ��ı���ʽ //��Ҫͳ��ͼ�бߵ�����������newlines���м�¼����Ŀ string sqlstr, tablename,vertex,adjvertex,tmpVertex; string[] tmpAdjVertex; DataTable tmpdt,tmpCount,tmpLength; int count,gid,vertexCount,edgeCount; tablename = layerName + "_newlines"; sqlstr="select count(*) from " + tablename; tmpdt = postDB.DoQueryEx(sqlstr); edgeCount = int.Parse(tmpdt.Rows[0]["count"].ToString()); tablename=layerName+"_vertex_adjaction"; sqlstr = "select vertex_id,vertex_adj_id from " + tablename + " " + "order by vertex_id asc"; tmpdt = postDB.DoQueryEx(sqlstr); vertexCount = tmpdt.Rows.Count; #region ���Դ��� //�˴���õ�edgeֵ��������newlines�ļ�¼�����˶δ��������� //gid = 0; //tablename = layerName + "_edge"; //sqlstr = "create table " + tablename + " (gid integer,point1 integer,point2 integer)"; //postDB.CheckCreateTable(tablename, sqlstr); //for (int i = 0; i < tmpdt.Rows.Count; i++) //{ // vertex = tmpdt.Rows[i]["vertex_id"].ToString(); // adjvertex = tmpdt.Rows[i]["vertex_adj_id"].ToString(); // tmpAdjVertex = adjvertex.Split('_'); // for (int j = 0; j < tmpAdjVertex.Length; j++) // { // tmpVertex = tmpAdjVertex[j]; // sqlstr = "select count(*) from " + tablename + " where point1=" + vertex + " " + "and point2=" + tmpVertex + " " + "or point1=" + " " + tmpVertex + " " + "and point2=" + vertex; // tmpCount = postDB.DoQueryEx(sqlstr); // count = int.Parse(tmpCount.Rows[0]["count"].ToString()); // if (count == 0) // { // gid++; // sqlstr = "insert into " + tablename + " (gid,point1,point2) values(" + gid.ToString() + "," + vertex + "," + tmpVertex + ")"; // postDB.ExecNonQuery(sqlstr); // } // } //} //sqlstr="select count(*) from " + tablename; //tmpCount = postDB.DoQueryEx(sqlstr); //edgeCount = int.Parse(tmpCount.Rows[0][0].ToString()); #endregion string fileName = layerName + "_MetisGraph.txt"; //��bin�ļ�����ͬһĿ¼�� string filePath = Application.StartupPath + "\\"; StreamWriter sw; if (! File.Exists(filePath+fileName)) { sw=File.CreateText(filePath + fileName); } else { sw = new StreamWriter(filePath + fileName, false); } sw.WriteLine(vertexCount.ToString() + " " + edgeCount.ToString() + " " + "001"); tablename=layerName+"_newlines"; for (int m = 0; m < vertexCount;m++ ) { int reLength; string formatStr,length; formatStr=""; vertex = tmpdt.Rows[m]["vertex_id"].ToString(); adjvertex = tmpdt.Rows[m]["vertex_adj_id"].ToString(); tmpAdjVertex = adjvertex.Split('_'); //Ҫ��Ȩֵ���������� for (int n = 0; n < tmpAdjVertex.Length;n++ ) { tmpVertex = tmpAdjVertex[n]; sqlstr="select length from " + tablename + " " + "where source=" + vertex + " " + "or target=" + tmpVertex + " " + "and source=" + tmpVertex + " " + "or target=" +vertex; tmpLength=postDB.DoQueryEx(sqlstr); length=tmpLength.Rows[0]["length"].ToString(); reLength = (int)double.Parse(length); formatStr +=tmpVertex+ " " + reLength.ToString() + " "; } formatStr.TrimEnd(' '); sw.WriteLine(formatStr); } sw.Close(); string algorithmName = this.cbxMetisAlgorithm.SelectedItem.ToString().Trim(); //���adj�����Ƿ���ӷ����ֶ� string colName = "metispartition_"+algorithmName; //string colName = "metispartition_rb"; tablename = layerName + "_vertex_adjaction"; if (postDB.IsColumnExist(tablename, colName)) { sqlstr = "alter table " + tablename + " " + "drop column " + colName + " cascade"; postDB.ExecNonQuery(sqlstr); sqlstr = "alter table " + tablename + " " + "add column " + colName + " integer"; postDB.ExecNonQuery(sqlstr); } else { sqlstr = "alter table " + tablename + " " + "add column " + colName + " integer"; postDB.ExecNonQuery(sqlstr); } //����gpmetis.exe�������������ݽ�ȥ���õ�������ȡ�ļ��������д�뵽adj���� //��Ϊ�����ò������˴�����Ϊ24 string npart = this.txtPartNum.Text.Trim(); string resultFileName = fileName + ".part." + npart; //������ļ��Ƿ���� if (File.Exists(filePath+resultFileName)) { File.Delete(filePath + resultFileName); } CmdOperation co = new CmdOperation(); //ʹ�����ַ�ʽkway��rb�㷨���л��� string[] cmd = new string[] { }; switch (algorithmName) { case "kway": cmd = new string[] { "cd /d " + filePath, "gpmetis " + fileName + " " + npart }; break; case "rb": cmd = new string[] { "cd /d " + filePath, "gpmetis -ptype=rb " + fileName + " " + npart }; break; default: break; } co.ExecuteCmd(cmd); //����ļ��Ƿ���ڣ��ж��Ƿ����ɹ� string subNum; int vertexId; if (File.Exists(filePath + resultFileName)) { StreamReader sr = new StreamReader(filePath + resultFileName, Encoding.UTF8); subNum = sr.ReadLine(); vertexId=1; while (subNum !=null) { sqlstr = "update " + " " + tablename + " " + "set" + " " + colName + "=" + subNum + " " + "where vertex_id=" + vertexId; postDB.ExecNonQuery(sqlstr); subNum = sr.ReadLine(); vertexId++; } } //������ɺ����ɶ�Ӧ�Ķ���� ComputePolygon(tablename, npart, algorithmName); GvwData.DataSource = GetData(tablename); //MessageBox.Show("���������"); }
//�������и����⣬�����ִ����kway��֮����ִ��rbʱ������ʾ˵�����ļ�����ʹ�ã��ļ���ʹ��û����ȫ�ͷ� private void btnMETISTest_Click(object sender, EventArgs e) { try { //���ݽ�����������������Ӧ�ķ����ļ�������������µ�level2_newlines_test���� string fileName = layerName + "_MetisGraph.txt"; //��bin�ļ�����ͬһĿ¼�� string filePath = Application.StartupPath + "\\"; string tablename = layerName + "_vertex_adjaction_test"; int start = 21; int stop = 30; string sqlstr; string algorithmName = this.cbxMetisAlgorithm.SelectedItem.ToString().Trim(); for (int i = start; i < stop; i++) { //���adj�����Ƿ���ӷ����ֶ� string colName = "metispartition_" + algorithmName + "_" + i.ToString(); if (postDB.IsColumnExist(tablename, colName)) { sqlstr = "alter table " + tablename + " " + "drop column " + colName + " cascade"; postDB.ExecNonQuery(sqlstr); sqlstr = "alter table " + tablename + " " + "add column " + colName + " integer"; postDB.ExecNonQuery(sqlstr); } else { sqlstr = "alter table " + tablename + " " + "add column " + colName + " integer"; postDB.ExecNonQuery(sqlstr); } //����gpmetis.exe�������������ݽ�ȥ���õ�������ȡ�ļ��������д�뵽adj���� string resultFileName = fileName + ".part." + i.ToString(); //������ļ��Ƿ���� if (File.Exists(filePath + resultFileName)) { File.Delete(filePath + resultFileName); } CmdOperation co = new CmdOperation(); //ʹ�����ַ�ʽkway��rb�㷨���л��� string[] cmd = new string[] { }; switch (algorithmName) { case "kway": cmd = new string[] { "cd /d " + filePath, "gpmetis " + fileName + " " + i.ToString() }; break; case "rb": cmd = new string[] { "cd /d " + filePath, "gpmetis -ptype=rb " + fileName + " " + i.ToString() }; break; default: break; } co.ExecuteCmd(cmd); //����ļ��Ƿ���ڣ��ж��Ƿ����ɹ� string subNum; int vertexId; if (File.Exists(filePath + resultFileName)) { StreamReader sr = new StreamReader(filePath + resultFileName, Encoding.UTF8); subNum = sr.ReadLine(); vertexId = 1; while (subNum != null) { sqlstr = "update " + " " + tablename + " " + "set" + " " + colName + "=" + subNum + " " + "where vertex_id=" + vertexId; postDB.ExecNonQuery(sqlstr); subNum = sr.ReadLine(); vertexId++; } } ComputePolygonTest(tablename, i.ToString(), algorithmName); string Max, Min, Median; ComputeStats(tablename, i.ToString(), algorithmName, out Max, out Min, out Median); fileName = algorithmName + "_stats_result.txt"; //��bin�ļ�����ͬһĿ¼�� filePath = Application.StartupPath + "\\"; StreamWriter sw; if (!File.Exists(filePath + fileName)) { sw = File.CreateText(filePath + fileName); } else { sw = new StreamWriter(filePath + fileName, true); } sw.WriteLine("{0}\t{1}\t{2}\t{3}", i.ToString(), Max, Min, Median); sw.Flush(); sw.Close(); } MessageBox.Show("�������"); } catch (System.Exception ex) { } finally { } }