import java.io.*; import java.util.*; /** * Data model of application. Other classes use data holded here. If runned * from main, then can make calculations self without graphics. */ public class OntoData{ double[][] data; double[][] coordinates; double[][] gps; int gpsPeopleNr=0; final int dimcount=2; final double maxcoord=100; // double[] perspective; //columns // String[] parameters; // int[] paramgroups; OntoParam[] params; String[] names; //rows String[] links; boolean[] locked; Vector[] comments; // String[] paramgroupnames; // double[] paramgroupcoefs; // int[] parentgroupids; //Vector paramgroupv=new Vector(); OntoParamGroup rootgroup=new OntoParamGroup("\\", 1, null); public static void main(String[] arg){ OntoData m=new OntoData(); // m.readDataFromFile("Creatures2.txt"); m.readDataFromFile("aj.txt"); m.normalizeData(); // m.perspective=new double[]{0, 0, 1, 0,0, 0, 0, 0}; m.randomCoordinates(); // m.position(0); m.writeDataToFile("test1.txt"); m.writeCoordinatesToFile("con"); } String getDataAsText(){ StringBuffer sb=new StringBuffer(); if(links!=null){ sb.append("\tlinks"); } for(int i=0; i0){ try{ String separator=" "; if(s.indexOf(",")>=0){separator=",";} if(s.indexOf(";")>=0){separator=";";} if(s.indexOf("\t")>=0){separator="\t";} Vector row=new Vector(); StringTokenizer stk2=new StringTokenizer(s, separator); while(stk2.hasMoreTokens()){ String s2=stk2.nextToken(); row.add(s2); } if(row.size()>0){ rows.add(row); } }catch(Exception rex){ System.out.println("Problem with row data "+rex.getMessage()); System.out.println(s); } } } if(rows.size()==0){ params=new OntoParam[0]; names=new String[0]; data=new double[0][0]; return; } rootgroup=new OntoParamGroup("\\", 1, null); Vector v0=(Vector)rows.get(0); if(v0.size()<1){throw new RuntimeException("invalid data");} boolean parametersExists=false; boolean linksExists=false; try{ Double.parseDouble((String)v0.get(1)); }catch(Exception ex){ parametersExists=true; // System.out.println("Parameetrid olemas"); } if(parametersExists){ //System.out.println(v0); if(v0.get(0).equals("links")){ linksExists=true; // System.out.println("Viited olemas"); v0.remove(0); } else { if(rows.size()>1){ // System.out.println("Pikkuse uuring "+v0.size()+" "+((Vector)rows.get(1)).size()); if(v0.size()==((Vector)rows.get(1)).size()){ //id tulba nimi ees v0.remove(0); // System.out.println("id maha"); } } } params=new OntoParam[v0.size()]; for(int i=0; i=2 && params[0].name.equals("gpsx") && params[1].name.equals("gpsy")){ gps=new double[data.length][2]; for(int j=0; j=rownr){newrow=j+1;} } else { if(j>=rownr){oldrow=j+1;} } newnames[newrow]=names[oldrow]; newlinks[newrow]=links[oldrow]; for(int i=0; i=colnr){newcol=j+1;} } else { if(j>=colnr){oldcol=j+1;} } /* newparameters[newcol]=parameters[oldcol]; newperspective[newcol]=perspective[oldcol]; newparamgroups[newcol]=paramgroups[oldcol]; */ newparams[newcol]=params[oldcol]; for(int i=0; i=paramgroupnames.length){ throw new RuntimeException("Too big group number"); } paramgroups[parameter]=groupnr; } */ /* int addParamGroup(String groupname){ String[] newgroupnames=new String[paramgroupnames.length+1]; double[] newgroupcoefs=new double[paramgroupcoefs.length+1]; int[] newparentgroupids=new int[paramgroupcoefs.length+1]; for(int i=0; i0){ throw new RuntimeException("Last group has "+count+" parameters"); } String[] newgroupnames=new String[paramgroupnames.length-1]; double[] newgroupcoefs=new double[paramgroupnames.length-1]; for(int i=0; imax){max=data[j][i];} } if(max>1){ for(int j=0; jmax){max=data[j][i];} if(data[j][i]0.001){ data[j][i]=(data[j][i]-min)/(max-min); } else { data[j][i]=0.5; } } } } void normalizeCoordinates(){ for(int i=0; imax){max=coordinates[j][i]; } } double koef=2*maxcoord/(max-min); double centre=(max+min)/2; for(int j=0; j100){delta=100;} double[] newloc=approach(a, b, delta*step); for(int i=0; i