$darkmode
DENOPTIM
CombinatorialExplorerByLayer.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.combinatorial;
20
21import java.io.File;
22import java.util.ArrayList;
23import java.util.Collection;
24import java.util.Collections;
25import java.util.HashMap;
26import java.util.List;
27import java.util.Map;
28import java.util.concurrent.ArrayBlockingQueue;
29import java.util.concurrent.Future;
30import java.util.concurrent.RejectedExecutionHandler;
31import java.util.concurrent.ThreadPoolExecutor;
32import java.util.concurrent.TimeUnit;
33import java.util.logging.Level;
34
35import org.apache.commons.io.FileUtils;
36import org.apache.commons.lang3.time.StopWatch;
37
38import denoptim.constants.DENOPTIMConstants;
39import denoptim.exception.DENOPTIMException;
40import denoptim.fragspace.FragmentSpaceParameters;
41import denoptim.fragspace.FragsCombination;
42import denoptim.fragspace.FragsCombinationIterator;
43import denoptim.fragspace.IdFragmentAndAP;
44import denoptim.graph.DGraph;
45import denoptim.graph.Vertex;
46import denoptim.graph.Vertex.BBType;
47import denoptim.io.DenoptimIO;
48import denoptim.programs.RunTimeParameters.ParametersType;
49import denoptim.programs.combinatorial.CEBLParameters;
50import denoptim.utils.GraphUtils;
51
52
62{
63
67 final Map<GraphBuildingTask,Future<Object>> submittedAndFutures;
68
72 final List<GraphBuildingTask> submitted;
73
77 final ThreadPoolExecutor tpe;
78
82 private int verbosity = 0;
83
87 private boolean restartFromChkPt = false;
88
93 private int serFromChkRestart = 0;
94
98 private int totSubmittedTasks = 0;
99
103 private Throwable thrownByTask;
104
108 private boolean firstAfterRestart = false;
109
113 private CEBLParameters settings = null;
114
119
120
121//-----------------------------------------------------------------------------
122
128 {
129 this.settings = settings;
130 this.verbosity = settings.getVerbosity();
131 this.restartFromChkPt = settings.restartFromCheckPoint();
132
135 {
138 }
139
140 submittedAndFutures = new HashMap<GraphBuildingTask,Future<Object>>();
141 submitted = new ArrayList<GraphBuildingTask>();
142
143 tpe = new ThreadPoolExecutor(settings.getNumberOfCPU(),
145 Long.MAX_VALUE,
146 TimeUnit.NANOSECONDS,
147 new ArrayBlockingQueue<Runnable>(1));
148
149 Runtime.getRuntime().addShutdownHook(new Thread()
150 {
151 @Override
152 public void run()
153 {
154 tpe.shutdown(); // Disable new tasks from being submitted
155 try
156 {
157 // Wait a while for existing tasks to terminate
158 if (!tpe.awaitTermination(30, TimeUnit.SECONDS))
159 {
160 tpe.shutdownNow(); // Cancel currently executing tasks
161 }
162
163 if (!tpe.awaitTermination(60, TimeUnit.SECONDS))
164 {
165 // pool didn't terminate after the second try
166 }
167 }
168 catch (InterruptedException ie)
169 {
170 cleanup();
171 // (Re-)Cancel if current thread also interrupted
172 tpe.shutdownNow();
173 // Preserve interrupt status
174 Thread.currentThread().interrupt();
175 }
176 }
177 });
178
179 // by default the ThreadPoolExecutor will throw an exception
180 tpe.setRejectedExecutionHandler(new RejectedExecutionHandler()
181 {
182 @Override
183 public void rejectedExecution(Runnable r,
184 ThreadPoolExecutor executor)
185 {
186 try
187 {
188 // this will block if the queue is full
189 executor.getQueue().put(r);
190 }
191 catch (InterruptedException ex)
192 {
193 if (verbosity > 1)
194 {
195 ex.printStackTrace();
196 String msg = "EXCEPTION in rejectedExecution.";
197 settings.getLogger().log(Level.WARNING,msg);
198 }
199 }
200 }
201 });
202 }
203
204//------------------------------------------------------------------------------
205
210 public void stopRun()
211 {
212 cleanup();
213 tpe.shutdown();
214 }
215
216//------------------------------------------------------------------------------
217
224 private boolean subtaskHasException()
225 {
226 boolean hasException = false;
227 for (GraphBuildingTask tsk : submitted)
228 {
229 if (tsk.foundException())
230 {
231 hasException = true;
232 thrownByTask = tsk.getException();
233 break;
234 }
235 }
236
237 return hasException;
238 }
239
240//------------------------------------------------------------------------------
241
247 private boolean allTasksCompleted()
248 {
249 boolean allDone = true;
250 for (GraphBuildingTask tsk : submitted)
251 {
252 if (!tsk.isCompleted())
253 {
254 allDone = false;
255 break;
256 }
257 }
258
259 return allDone;
260 }
261
262//------------------------------------------------------------------------------
263
269 private void makeCheckPoint() throws DENOPTIMException
270 {
271 for (int i=0; i<submitted.size(); i++)
272 {
273 GraphBuildingTask tsk = submitted.get(i);
274 int idToChkPt = -1;
275 boolean storeChkPt = false;
276 if (!tsk.isCompleted() && i>0)
277 {
278 if (submitted.get(i-1).isCompleted())
279 {
280 // The last completed task preceding the first uncompleted
281 idToChkPt = i-1;
282 storeChkPt = true;
283 }
284 }
285 else if (tsk.isCompleted() && (i==submitted.size()-1))
286 {
287 idToChkPt = i;
288 storeChkPt = true;
289 }
290 if (storeChkPt)
291 {
292 tsk = submitted.get(idToChkPt);
295 chk.setRootId(tsk.getRootId());
296 chk.setNextIds(tsk.getNextIds());
297 chk.setLevel(tsk.getLevel());
302 break;
303 }
304 }
305
306 //Clean up list of submitted tasks
307 List<GraphBuildingTask> completed = new ArrayList<GraphBuildingTask>();
308 for (GraphBuildingTask tsk : submitted)
309 {
310 if (tsk.isCompleted())
311 {
312 totSubmittedTasks = totSubmittedTasks + tsk.getNumberOfSubTasks();
313 completed.add(tsk);
314 }
315 }
316 submitted.removeAll(completed);
317 for (GraphBuildingTask removable : completed)
318 {
319 submittedAndFutures.get(removable).cancel(true);
320 submittedAndFutures.remove(removable);
321 }
322 }
323
324//------------------------------------------------------------------------------
325
332 private int countSubTasks()
333 {
334 int tot = totSubmittedTasks;
335 //We add those that have not being counted yet.
336 for (GraphBuildingTask tsk : submitted)
337 {
338 tot = tot + tsk.getNumberOfSubTasks();
339 }
340 return tot;
341 }
342
343//------------------------------------------------------------------------------
344
349 public void run() throws DENOPTIMException
350 {
351 String msg = "";
352 StopWatch watch = new StopWatch();
353 watch.start();
354
355 tpe.prestartAllCoreThreads();
356
357 int level = -1;
359 {
360 firstAfterRestart = true;
362 level = chk.getLevel();
366
367 msg = "Restarting Combinatorial job from checkpoint file. "
368 + DENOPTIMConstants.EOL
369 + "All graphs with ID higher than "
371 + " are now being re-generated. Be aware that this "
372 + "includes graphs managed either by "
373 + "partially executed or completed tasks of the previous "
374 + "run. "
375 + DENOPTIMConstants.EOL
376 + "To avoid duplicates, you should remove from the results "
377 + "of the previos run all graphs with ID higher than "
379 + ". You can find them in the "
380 + "index file ('" + DENOPTIMConstants.FSEIDXNAMEROOT + level
381 + ".txt')."
382 + DENOPTIMConstants.EOL
383 + "Now reading '" + DENOPTIMConstants.SERGFILENAMEEXT + "' "
384 + "files from '"
385 + CEBLUtils.getNameOfStorageDir(settings, level) + "'.";
386 settings.getLogger().log(Level.WARNING,msg);
387
388 if (!denoptim.files.FileUtils.checkExists(
390 {
391 msg = "ERROR! Folder '"
393 + "' does not exist! Use 'FSE-DBROOTFOLDER' to "
394 + "provide the pathname to the existing folder where "
395 + "the previously generated graphs are located.";
396 settings.getLogger().log(Level.SEVERE,msg);
397 throw new DENOPTIMException(msg);
398 }
399
400 Collection<File> lst = FileUtils.listFiles(
401 new File(CEBLUtils.getNameOfStorageDir(settings, level)),
402 new String[] {DENOPTIMConstants.SERGFILENAMEEXT},false);
403 // Keep only safely completed serialized graphs
404 serFromChkRestart = lst.size();
405 for (File f : lst)
406 {
407 String fName = f.getName();
408 int serGrphID = Integer.parseInt(fName.substring(
410 fName.length()
411 - DENOPTIMConstants.SERGFILENAMEEXT.length()-1));
412 if (serGrphID > chk.getLatestSafelyCompletedGraphId())
413 {
414 msg = "Removing non-safely completed graph '" + fName + "'";
415 settings.getLogger().log(Level.WARNING,msg);
417 denoptim.files.FileUtils.deleteFile(
419 + File.separator + fName);
420 }
421 }
422 }
423
424 boolean interrupted = false;
425 while (level <= settings.getMaxLevel())
426 {
427 msg = "Starting exploration of level " + level;
428 settings.getLogger().log(Level.INFO,msg);
429
430 int numSubTasks = exploreCombinationsAtGivenLevel(level);
431
432 if (numSubTasks > 0)
433 {
434 // wait for pending tasks to finish
435 long startTime = System.currentTimeMillis();
436 while (true)
437 {
438 long endTime = System.currentTimeMillis();
439 long millis = (endTime - startTime);
440 if (allTasksCompleted())
441 {
442 Collection<File> lst = FileUtils.listFiles(
444 settings, level)),
446 false);
447 int outCount = lst.size() - serFromChkRestart;
448 int totSubmSubTasks = countSubTasks();
449 if (outCount != totSubmSubTasks && level > -1)
450 {
451 msg = "Mismatch between the number of submitted "
452 + "tasks (" + totSubmSubTasks + ") and those "
453 + "listed in "
455 + "(" + outCount + ")";
456 settings.getLogger().log(Level.SEVERE,msg);
457 throw new DENOPTIMException(msg);
458 }
459 break;
460 }
461 else
462 {
464 {
465 stopRun();
466 msg = "Exception in submitted task.";
467 throw new DENOPTIMException(msg,thrownByTask);
468 }
469 }
470
471 if (verbosity > 0)
472 {
473 msg = "Waiting for completion of level " + level;
474 msg = msg + String.format(" (elapsed %d min, %d sec)",
475 TimeUnit.MILLISECONDS.toMinutes(millis),
476 TimeUnit.MILLISECONDS.toSeconds(millis)
477 - TimeUnit.MINUTES.toSeconds(
478 TimeUnit.MILLISECONDS.toMinutes(millis)));
479 settings.getLogger().log(Level.INFO,msg);
480 }
481
482 if (millis > settings.getMaxWait())
483 {
484 stopRun();
485 msg = "Timeout reached: stopping all subtasks.";
486 settings.getLogger().log(Level.SEVERE, msg);
487 interrupted = true;
488 break;
489 }
490
491 try
492 {
493 Thread.sleep(settings.getWaitStep());
494 }
495 catch (Throwable t)
496 {
497 throw new DENOPTIMException(t);
498 }
499 }
500 }
501
502 // Clean queue
503 cleanup();
504
505 // Level and all tasks completed
506 if (interrupted)
507 {
508 break;
509 }
510 else
511 {
512 msg = "Exploration of level " + level + " "
513 + "completed" + DENOPTIMConstants.EOL
514 + "----------------------------------------"
515 + "----------------------------------------"
517 settings.getLogger().log(Level.INFO,msg);
518 }
519
520 // Increment level index
521 level++;
522
523 // Check for possibility of building another level
524 boolean noRoot = false;
525 if (numSubTasks == 0)
526 {
527 // Needed to perceive prev.lev. when restarting from checkpoint
528 try
529 {
530 Collection<File> lstRootsForNextLev = FileUtils.listFiles(
532 level-1)),
533 new String[] {DENOPTIMConstants.SERGFILENAMEEXT},
534 false);
535 if (lstRootsForNextLev.size() == 0)
536 {
537 noRoot = true;
538 }
539 }
540 catch (Throwable t)
541 {
542 noRoot = true;
543 }
544 }
545 if (noRoot)
546 {
547 msg = "Previous level did not return any extendable graph. "
548 + "Terminating exploration." + DENOPTIMConstants.EOL
549 + "----------------------------------------"
550 + "----------------------------------------"
552 settings.getLogger().log(Level.INFO,msg);
553 break;
554 }
555
557 {
558 restartFromChkPt = false;
559 }
560 }
561
562 // shutdown thread pool
563 tpe.shutdown();
564
565 // closing messages
566 watch.stop();
567 msg = "Overall time: " + watch.toString() + ". "
568 + DENOPTIMConstants.EOL
569 + "FragSpaceExplorer run completed." + DENOPTIMConstants.EOL;
570 settings.getLogger().log(Level.INFO, msg);
571 }
572
573//------------------------------------------------------------------------------
574
584 private int exploreCombinationsAtGivenLevel(int level)
585 throws DENOPTIMException
586 {
587 // The very first level only has the scaffold or the user defined roots
588 if (level == -1)
589 {
590 ArrayList<DGraph> scafLevel = new ArrayList<DGraph>();
592 {
593 // User defined root graphs
594 if (verbosity > 0)
595 {
596 String msg = "User defined root graphs are treated as "
597 + "if they were scaffolds. "
598 + "That is, the 'level' of the available attachment "
599 + "points is considered to be '-1' "
600 + "no matter what is the actual level of such APs "
601 + "in the root graph.";
602 settings.getLogger().log(Level.WARNING, msg);
603 }
604 for (DGraph rootGraph : settings.getRootGraphs())
605 {
606 // Vertex ID in root can be whatever and we ignore them
607 // when setting new vertex IDs. To do this, we change sign
608 // to the old IDs to avoid them clashing with the new ones,
609 rootGraph.changeSignOfVertexID();
610 // ...and re-assign all IDs
611 rootGraph.renumberGraphVertices();
612 rootGraph.setGraphId(GraphUtils.getUniqueGraphIndex());
613 scafLevel.add(rootGraph);
614 }
615 }
616 else
617 {
618 // Make the root graphs from the scaffolds
619 for (int i=0; i<fsSettings.getFragmentSpace()
620 .getScaffoldLibrary().size(); i++)
621 {
622 scafLevel.add(startNewGraphFromScaffold(i));
623 }
624 }
625
626 // Store them
627 CEBLUtils.storeAllGraphsOfLevel(settings, scafLevel,level);
628
629 // All done
630 return scafLevel.size();
631 }
632
633 // Iterate through the previous level
634 String msg = "";
635 int numSubTasks = 0;
636 int cntRoot = 0;
637 int total = 0;
638 int itersFromChkPt = 0;
639 String prevLevDirName = CEBLUtils.getNameOfStorageDir(settings,level-1);
640 if (!denoptim.files.FileUtils.checkExists(prevLevDirName))
641 {
642 msg = "Previous level folder '" + prevLevDirName + "' not found!";
643 throw new DENOPTIMException(msg);
644 }
645 Collection<File> files = FileUtils.listFiles(new File(prevLevDirName),
646 new String[] {DENOPTIMConstants.SERGFILENAMEEXT}, false);
647 ArrayList<File> lstFiles = new ArrayList<File>(files);
648 Collections.sort(lstFiles);
649 for (File file : lstFiles)
650 {
651 cntRoot++;
652 if (restartFromChkPt &&
653 settings.getCheckPoint().serFileAlreadyUsed(file.getName()))
654 {
655 continue;
656 }
657
659 file.getAbsolutePath()).get(0);
660
661 // Get combination factory
663 fsSettings, rootGraph);
664
666 {
667 firstAfterRestart = false;
669 .getNextIds());
670 }
671
672 // Print summary
673 if (settings.getLogger().isLoggable(Level.FINE))
674 {
675 StringBuilder sb = new StringBuilder(512);
676 sb.append("Root: " + file.getName() + DENOPTIMConstants.EOL);
677 sb.append(" - #Usable APs on root = ");
678 sb.append(fcf.getNumRootAPs() + DENOPTIMConstants.EOL);
679 sb.append(" - Size of candidates sets = ");
681 sb.append(" - Total #Combinations = ");
682 sb.append(fcf.getTotNumbCombs() + DENOPTIMConstants.EOL);
683 sb.append(" - Root graph: " + DENOPTIMConstants.EOL+rootGraph);
684 sb.append(DENOPTIMConstants.EOL);
685 sb.append(" - Details for root APs:");
686 sb.append(DENOPTIMConstants.EOL);
687 Map<IdFragmentAndAP, ArrayList<IdFragmentAndAP>> m =
688 fcf.getCandidatesMap();
689 for (IdFragmentAndAP srcAP : m.keySet())
690 {
691 sb.append(" -> "+srcAP).append(DENOPTIMConstants.EOL);
692 int iTrgAP = 0;
693 for (IdFragmentAndAP trgAP : m.get(srcAP))
694 {
695 iTrgAP++;
696 sb.append(" " + iTrgAP + " -> "+trgAP);
697 sb.append(DENOPTIMConstants.EOL);
698 }
699 }
700 settings.getLogger().log(Level.FINE, sb.toString()
702 }
703
704 // Iterate over all combinations
705 try
706 {
707 while (fcf.hasNext())
708 {
710 {
711 stopRun();
712 msg = "Exception in submitted task.";
713 throw new DENOPTIMException(msg,thrownByTask);
714 }
715
716 FragsCombination fragsToAdd = fcf.next();
717
719 settings,
720 rootGraph, fragsToAdd, level,
723
724 ArrayList<Integer> nextIds = fcf.getNextIds();
725 task.setNextIds(nextIds);
726
727 submittedAndFutures.put(task, tpe.submit(task));
728 submitted.add(task);
729
730 numSubTasks++;
731 if (itersFromChkPt >= settings.getCheckPointStep())
732 {
733 itersFromChkPt = 0;
735 }
736 itersFromChkPt++;
737
738 // Code meant only for preparation of checkpoint files
739 // The two following variables define at which point in the
740 // exploration of the space we want to stop.
741 int maxL = 2;
742 int maxI = 50;
744 {
745 System.out.println("Wait until "+level+"=="+maxL+" and "
746 +(total+fcf.getNumGeneratedCombs())+"=="+maxI);
747 if (level>=maxL &&
748 (total+fcf.getNumGeneratedCombs()>=maxI))
749 {
750 System.out.println("Execution stopped: now waiting "
751 + " for checkpoint file to mature");
752 int iWait=0;
753 int nEqual = 0;
754 ArrayList<Integer> oldIds =new ArrayList<Integer>();
755 ArrayList<Integer> nowIds =new ArrayList<Integer>();
757 oldIds.addAll(settings.getCheckPoint().getNextIds());
758 while (true)
759 {
760 iWait++;
761 Thread.sleep(1000); // in millisec
762 if (iWait > 120)
763 {
764 System.out.println("NOT CONVERGED");
765 throw new DENOPTIMException("Generation of "
766 + "checkpoint file did not "
767 + "converge.");
768 }
770 nowIds.clear();
771 nowIds.addAll(
773 System.out.println(oldIds + " " + nowIds
774 + " nEqualChecks:" + nEqual);
775 boolean converged = true;
776 if (nowIds.size() != oldIds.size())
777 {
778 converged = false;
779 }
780 else
781 {
782 for (int iId=0; iId<nowIds.size(); iId++)
783 {
784 if (nowIds.get(iId) != oldIds.get(iId))
785 {
786 nEqual = 0;
787 converged = false;
788 break;
789 }
790 }
791 }
792 if (!converged)
793 {
794 oldIds.clear();
795 oldIds.addAll(nowIds);
796 continue;
797 }
798 nEqual++;
799 if (nEqual >= 10)
800 {
801 break;
802 }
803 }
804 System.out.println("Stopped with converged "
805 + "checkpoint IDs: " + nowIds);
806 throw new DENOPTIMException("Stopping due to "
807 + "request of generating checkpoint data "
808 + "for testing purposes");
809 }
810 }
811 }
812 }
813 catch (DENOPTIMException dex)
814 {
815 cleanup();
816 tpe.shutdown();
817 throw dex;
818 }
819 catch (Exception ex)
820 {
821 cleanup();
822 tpe.shutdown();
823 throw new DENOPTIMException(ex);
824 }
825
826 msg = fcf.getNumGeneratedCombs() + "/"
827 + fcf.getTotNumbCombs() + " combination generated "
828 + "for level " + level + " of graph " + cntRoot;
829 settings.getLogger().log(Level.FINE, msg);
830 total = total + fcf.getNumGeneratedCombs();
831 }
832
833 msg = "Total number of combination of fragments generated "
834 + "for level " + level + " = " + total;
835 settings.getLogger().log(Level.INFO, msg);
836
837/*
838 // Code meant only to generate checkpoint file at the end of a level
839 if (settings.prepareFilesForTests())
840 {
841 System.out.println("Last submissions for level "+level+". Wait for "
842 + "completion of the tasks.");
843 while (true)
844 {
845 makeCheckPoint();
846 System.out.println("Ctrl-Z once converged: " +
847 settings.getCheckPoint().getNextIds());
848 GenUtils.pause();
849 }
850 }
851*/
852
853 return numSubTasks;
854 }
855
856//------------------------------------------------------------------------------
857
863 private DGraph startNewGraphFromScaffold(int scafIdx)
864 throws DENOPTIMException
865 {
866 DGraph molGraph = new DGraph();
868
872
873 // add the scaffold as a vertex
874 molGraph.addVertex(scafVertex);
875 molGraph.setLocalMsg("NEW");
876
877 return molGraph;
878 }
879
880//------------------------------------------------------------------------------
881
886 private void cleanup()
887 {
889 {
890 tsk.stopTask();
891 submittedAndFutures.get(tsk).cancel(true);
892 submittedAndFutures.remove(tsk);
893 }
894
895 submitted.clear();
896
897 tpe.getQueue().clear();
898 }
899
900//------------------------------------------------------------------------------
901
902}
Helper methods for the exploration of the fragment space.
Definition: CEBLUtils.java:45
static void storeAllGraphsOfLevel(CEBLParameters settings, ArrayList< DGraph > lstGraphs, int level)
Serialize all DENOPTIMGraphs to file.
Definition: CEBLUtils.java:156
static String getNameOfStorageDir(CEBLParameters settings, int level)
Definition: CEBLUtils.java:54
static void serializeCheckPoint(CEBLParameters settings)
Store the checkpoint in a text file with json format.
Definition: CEBLUtils.java:222
Object collecting information needed to restart a FragSpaceExplorer job.
Definition: CheckPoint.java:40
void setNextIds(ArrayList< Integer > nextIds)
Set the indexes that identify the combination of fragments next to the latest one that has been prope...
void setUnqGraphId(int val)
Set the restart value for the unique graph ID.
void setSafelyCompletedGraphId(int val)
Set the graphId of the safely completed graph.
ArrayList< Integer > getNextIds()
boolean serFileAlreadyUsed(String filename)
void setLevel(int level)
Set the current level.
void setUnqMolId(int val)
Set the restart value for the unique molecule ID.
void setRootId(int val)
Set the graph ID of the root graph used to build this task.
void setUnqVrtId(long l)
Set the restart value for the unique vertex ID.
Generates all combinators of fragments by means of asynchronous threads.
boolean firstAfterRestart
Flag identifying the first iteration after restart from checkpoint.
int serFromChkRestart
Number of serialized graphs recovered from previous run database upon restart from checkpoint file.
FragmentSpaceParameters fsSettings
Settings and definition of the fragment space.
final List< GraphBuildingTask > submitted
Sorted list of subtasks.
void makeCheckPoint()
Identify the task preceding the earliest non-completed task and use it to create a checkpoint file.
void cleanup()
clean all reference to submitted tasks
final Map< GraphBuildingTask, Future< Object > > submittedAndFutures
Submitted subtasks and their futures.
boolean subtaskHasException()
Looks for exceptions in the subtasks and, if any, store its reference locally to allow reporting it b...
boolean allTasksCompleted()
Check for completion of all subtasks.
Throwable thrownByTask
If any, here we stores the exception returned by a subtask.
CEBLParameters settings
All settings controlling the tasks executed by this class.
int totSubmittedTasks
Number of tasks submitted directly of by subtasks.
void stopRun()
Stops all subtasks and shutdown executor.
boolean restartFromChkPt
Flag indicating to restart from checkpoint file.
int exploreCombinationsAtGivenLevel(int level)
Generate graphs by exploring all combination of fragments at a given level of a growing graph.
final ThreadPoolExecutor tpe
Asynchronous tasks manager.
Task that builds a graph by appending a given combination of fragments onto a given list of attachmen...
ArrayList< Integer > getNextIds()
Returns the set of indeces that identify the position of the the (next) combination of fragment in th...
int getRootId()
Returns the graphID of the root graph.
void setNextIds(ArrayList< Integer > nextIds)
Set the set of indexes that identify the position of the the (next) combination of fragment in the sp...
int getGraphId()
Returns the graphID of the original graph or of the latest cyclic alternative.
General set of constants used in DENOPTIM.
static final String SERGFILENAMEEXT
Extension filenames of serialized graphs.
static final String EOL
new line character
static final String SERGFILENAMEROOT
Prefix filenames of serialized graphs.
Parameters defining the fragment space.
Data structure identifying a combination of one or more pairs of attachment points located on specifi...
FragsCombination next()
Generate the next combination of fragments.
Map< IdFragmentAndAP, ArrayList< IdFragmentAndAP > > getCandidatesMap()
ArrayList< Integer > getNextIds()
Returns the list of indeces used to calculate the next iteration.
void setStartingPoint(ArrayList< Integer > nextIds)
Sets the starting point for the iterator.
Data structure containing information that identifies a single AP of a vertex/fragment.
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
Definition: DGraph.java:1097
void setGraphId(int id)
Definition: DGraph.java:258
void setLocalMsg(String msg)
Definition: DGraph.java:272
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
Definition: Vertex.java:214
Utility methods for input/output.
static ArrayList< DGraph > readDENOPTIMGraphsFromJSONFile(String fileName)
Reads a list of DGraphs from a JSON file.
boolean containsParameters(ParametersType type)
String getWorkDirectory()
Gets the pathname to the working directory.
RunTimeParameters getParameters(ParametersType type)
Logger getLogger()
Get the name of the program specific logger.
int getVerbosity()
Returns the level of verbosity, i.e., the amount of log that we want to print.
Parameters controlling execution of the combinatorial algorithm for exploration of a fragment space b...
boolean useGivenRoots
Flag declaring that generation of graphs will use a given list of graphs as starting points for the e...
boolean isCompleted()
Definition: Task.java:134
Utilities for graphs.
Definition: GraphUtils.java:40
static synchronized void resetUniqueGraphCounter(int val)
Reset the unique graph counter to the given value.
static synchronized long getUniqueVertexIndex()
Unique counter for the number of graph vertices generated.
Definition: GraphUtils.java:97
static synchronized void resetUniqueMoleculeCounter(int val)
Reset the unique mol counter to the given value.
static synchronized int getUniqueMoleculeIndex()
Unique counter for the number of molecules generated.
static synchronized void resetUniqueVertexCounter(long l)
Reset the unique vertex counter to the given value.
Definition: GraphUtils.java:77
static synchronized int getUniqueGraphIndex()
Unique counter for the number of graphs generated.
The type of building block.
Definition: Vertex.java:86
FS_PARAMS
Parameters pertaining the definition of the fragment space.