' Name : Spiderpmed.ave ' Title : Create spider diagrams ' ' Topics: Analysis ' ' Description: Creates spider diagrams based on the chosen theme, and the results ' generated by the Dmatrix and the Pmedian.exe programs written in C, that calculates ' the best point(s) using the heuristic solution for the p-median problem. The Output is a ' new (spider) theme with distances stored in the FTAB of Solução theme. ' ' Requires: ' ' Self: ' ' Returns: listamedianas = {} PointList = {} DistanceList = {} v = av.GetActiveDoc 'Escolha do numero de medianas e do tema a ser usado como pontos themeList = v.GetThemes while (true) smedianas= msgbox.input("Número de medianas:", "Selecione o numero de medianas", "1") if ( smedianas = nil) then exit else if ( smedianas.IsNumber) then nummedianas = smedianas.asnumber break else resposta=msgbox.info("Deve ser um valor numérico.","ERRO") end end end p = Msgbox.Choice (themeList, "Selecione o tema a ser usado como pontos.", "Selecione um tema") if (p = nil) then exit end Tp = v.FindTheme(p.AsString) Proj = v.GetProjection TpFTab = Tp.GetFTab ShpFldP = Tp.GetFTab.FindField("Shape") 'Gravação dos pontos no arquivo Pmedian.txt lf = LineFile.Make("pmedian.txt".AsFileName,#file_perm_write) if (lf = nil) then MsgBox.Error("Não pode abrir arquivo: pmedian.txt","") exit end npontos = Tp.GetFTab.GetNumRecords lf.writeElt(npontos.AsString++smedianas) for each r in TpFTab shpP = Tp.GetFTab.ReturnValue(ShpFldP, r) xcoord = shpP.GetX.AsString ycoord = shpP.GetY.AsString lf.WriteElt(xcoord++ycoord) end lf.close 'Execução do programa em linguagem C dmatrix.exe system.executeSynchronous("dmatrix.exe") 'Execução do programa em linguagem C pmedian.exe system.executeSynchronous("pmedian.exe") 'Leitura das respostas do pmedian solucao = textfile.make("solucao.txt".asfilename,#file_perm_read) aux = -1 while (true) med = solucao.read(7).Asnumber if (med = 9999999) then break end ponto = solucao.read(7).Asnumber dist = solucao.read(11) shpC = Tp.GetFtab.ReturnValue(ShpFldP,med) if ( med <> aux) then aux = med listamedianas.add(med) end shpP = Tp.GetFtab.ReturnValue(ShpFldP,ponto) Proj.Projectpt(shpC) Proj.Projectpt(shpP) PointList.Add(shpC) PointList.Add(shpP) DistanceList.Add(dist) solucao.skipline end solucao.skipline status = solucao.read(1) solucao.close listamedianas.sort(true) 'Utilização do spider para visualização da resposta 'Criação do tema com as medianas class = point def = av.GetProject.MakeFileName("Medianas", "shp") if (def <> nil) then test = Ftab.MakeNew(def, class) fld1 = Field.Make("ponto", #field_decimal, 8, 0) fld1.seteditable(true) fld1.SetVisible(true) test.AddFields({fld1}) resp = Ftheme.Make(test) k = 0 h = 0 for each r in TpFtab if (k <= (nummedianas-1)) then g = listamedianas.get(k) if (g = (r)) then pont = Tp.GetFtab.ReturnValue(ShpFldP, r) h = resp.getftab.findfield("shape") resp.getftab.SetValue (h, k, pont) f = resp.getftab.findfield("ponto") resp.getftab.addrecord k = k+1 end end end v.AddTheme(resp) resp.setactive(true) resp.setvisible(true) v.SetEditableTheme(resp) av.GetProject.SetModified(true) end Proj = v.GetProjection TcFtab = resp.GetFtab ShpFldC = resp.GetFtab.FindField("shape") d = av.getactivedoc.getdisplay 'make a new theme class = PolyLine def = av.GetProject.MakeFileName("solução", "shp") if (def <> nil) then tbl = Ftab.MakeNew(def, class) fld = Field.Make("ID", #field_decimal, 8, 0) fld2 = Field.Make("Distance", #field_double, 8, 0) fld.SetVisible( false ) tbl.AddFields({fld}) SpiderTheme = FTheme.Make(tbl) v.AddTheme(SpiderTheme) SpiderTheme.SetActive(true) SpiderTheme.SetVisible(false) v.SetEditableTheme(SpiderTheme) av.GetProject.SetModified(true) end themeList = v.GetThemes themeList.Shuffle( themeList.Get(0), (themeList.Count - 1)) v.InvalidateTOC ( nil ) 'Draw the spider diagrams ln = PointList.Count for each num in 1..ln by 2 shpC = PointList.get(num-1) shpP = PointList.get(num) spiderline = PolyLine.make( {{shpC, shpP}} ) theTheme = v.GetEditableTheme if (spiderline <> nil) then if (SpiderTheme <> nil) then if (Proj.IsNull.Not) then spiderline = spiderline.ReturnUnprojected(Proj) end theField = SpiderTheme.GetFtab.FindField("Shape") rec = SpiderTheme.GetFtab.AddRecord SpiderTheme.GetFtab.SetValue(theField, rec, spiderline) SpiderTheme.GetFtab.GetSelection.ClearAll SpiderTheme.GetFtab.GetSelection.Set(rec) SpiderTheme.GetFtab.UpdateSelection else gl = GraphicShape.Make(spiderline) v.GetGraphics.UnselectAll gl.SetSelected(true) v.GetGraphics.Add(gl) end av.GetProject.SetModified(true) end end '(FOR) 'Add the distance field and distances to the Ftab theFtab = SpiderTheme.GetFtab f1 = Field.Make ("Distance",#field_float,12,2) theFtab.SetEditable(true) theFtab.AddFields ({f1}) DistanceFld = theFTab.FindField("Distance") for each r in theFTab Dist = DistanceList.get(r) theFTab.SetValue (DistanceFld,r,Dist) end theFTab.SetEditable(false) SpiderTheme.SetVisible(true) 'Avaliação se a solução é ótima ou não nstatus = status.asnumber if (nstatus = 2) then msg = "Solução não ótima" else if (nstatus = 0) then msg = "Soluçào ótima do dual" else msg = "Solução ótima do primal" end end msgbox.info(msg,"Solução")