@@ -128,68 +128,40 @@ public int[][] postprocessCompleteGraph(Graph graph, MasterJJob masterJJob) thro
128128
129129 start = System .currentTimeMillis ();
130130 for (int i = 0 ; i < graph .getSize (); ++i ) {
131- for (int j = i + 1 ; j < graph .getSize (); ++j ) {
132- double a = graph .getLogWeight (i , j );
133- double b = graph .getLogWeight (j , i );
131+ int [] connections = graph .getLogWeightConnections (i );
132+ for (int j = 0 ; j < connections .length ; j ++) {
133+ int c = connections [j ];
134+
135+ //check if this pair of edges has already beend considered
136+ if (c <i && graph .hasLogWeightConnections (c , i )) continue ;
137+
138+ double a = graph .getLogWeight (i , c );
139+ double b = graph .getLogWeight (c , i );
134140 double max ;
135141 if (a < b ) {
136- graph .setLogWeight (i , j , b );
142+ graph .setLogWeight (i , c , b );
137143 max = b ;
138144 } else if (b < a ) {
139- graph .setLogWeight (j , i , a );
145+ graph .setLogWeight (c , i , a );
140146 max = a ;
141147 } else {
142148 max = a ;
143149 }
144150
145151 if (max > 0.0D ) {
146- connectionsList [i ].add (j );
147- connectionsList [j ].add (i );
152+ connectionsList [i ].add (c );
153+ connectionsList [c ].add (i );
148154 } else if (max < 0d ) {
149155 throw new RuntimeException ("Edge has a negative weight" );
150156 }
151157 }
152158 }
153159
154- //todo errors with parallelization.
155- // allIndices = new ArrayList<>(graph.getSize());
156- // for (int i = 0; i < graph.numberOfCompounds(); i++) {
157- // allIndices.add(i);
158- // }
159- // System.out.println("size "+allIndices.size());
160- // ConcurrentLinkedQueue<Integer> candidateIndicesQueue = new ConcurrentLinkedQueue<>(allIndices);
161- // System.out.println("size2 "+candidateIndicesQueue.size());
162- // jobs = new ArrayList<>();
163- // for (int i = 0; i < SiriusJobs.getGlobalJobManager().getCPUThreads(); i++) {
164- // BasicJJob job = new MakeEdgeScoresSymmetricWorker(candidateIndicesQueue, graph, connectionsList);
165- // jobs.add(job);
166- // masterJJob.submitSubJob(job);
167- // }
168- // System.out.println("running "+jobs.size()+" workers to postprocess edges, symmetry step");
169- //
170- //
171- // for (BasicJJob job : jobs) {
172- // job.awaitResult();
173- // }
174- //
175- // for (TIntArrayList intArrayList : connectionsList) {
176- // intArrayList.sort();
177- // }
178- System .out .println ("postprocess: second step symmetry took " +(System .currentTimeMillis ()-start ));
179160
161+ System .out .println ("postprocess: second step symmetry took " +(System .currentTimeMillis ()-start ));
180162
181- // candidateIndicesQueue = new ConcurrentLinkedQueue<>(allIndices);
182- // System.out.println("size3 "+candidateIndicesQueue.size());
183163 int [][] connections = new int [graph .getSize ()][];
184- // jobs = new ArrayList<>();
185- // for (int i = 0; i < SiriusJobs.getGlobalJobManager().getCPUThreads(); i++) {
186- // BasicJJob job = new CopyArrayJob(connections, connectionsList, candidateIndicesQueue);
187- // jobs.add(job);
188- // masterJJob.submitSubJob(job);
189- // }
190- // for (BasicJJob job : jobs) {
191- // job.awaitResult();
192- // }
164+
193165 for (int i = 0 ; i < graph .getSize (); ++i ) {
194166 connections [i ] = connectionsList [i ].toArray ();
195167 }
0 commit comments