From: <jen...@us...> - 2008-09-15 11:19:43
|
Revision: 1210 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1210&view=rev Author: jenslehmann Date: 2008-09-15 11:19:37 +0000 (Mon, 15 Sep 2008) Log Message: ----------- improved starting and stopping algorithms in GUI Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/StatisticsThread.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java trunk/src/dl-learner/org/dllearner/gui/ThreadStatistics.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-09-15 09:20:10 UTC (rev 1209) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-09-15 11:19:37 UTC (rev 1210) @@ -283,6 +283,7 @@ } public void start() { + stop = false; isRunning = true; runtime = System.currentTimeMillis(); Monitor totalLearningTime = JamonMonitorLogger.getTimeMonitor(ExampleBasedROLComponent.class, "totalLearningTime") Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-09-15 09:20:10 UTC (rev 1209) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-09-15 11:19:37 UTC (rev 1210) @@ -72,9 +72,9 @@ private boolean[] isEnabled = new boolean[4]; // learning algorithm status - private boolean threadIsRunning = false; - private Long algorithmRunStartTime = null; - private Long algorithmRunStopTime = null; +// private boolean threadIsRunning = false; +// private Long algorithmRunStartTime = null; +// private Long algorithmRunStopTime = null; private StartGUI gui; @@ -409,6 +409,7 @@ * * @param isThreadRunning */ + /* public void setThreadIsRunning(Boolean isThreadRunning) { if (isThreadRunning) algorithmRunStartTime = System.nanoTime(); @@ -416,16 +417,17 @@ if (algorithmRunStartTime < System.nanoTime()) algorithmRunStopTime = System.nanoTime(); this.threadIsRunning = isThreadRunning; - } + }*/ /** * Get true if algorithm has started, false if not. * * @return true if algorithm is running, false if not. */ + /* public Boolean getThreadIsRunning() { return this.threadIsRunning; - } + }*/ /** * Get time in ns for run of algorithm. If algorithm is still running return @@ -433,6 +435,7 @@ * * @return time in ns */ + /* public Long getAlgorithmRunTime() { if (algorithmRunStartTime != null) if (algorithmRunStopTime != null) { @@ -441,7 +444,7 @@ } else return System.nanoTime() - algorithmRunStartTime; return null; - } + }*/ /** * It is necessary for init LearningProblem. Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-09-15 09:20:10 UTC (rev 1209) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-09-15 11:19:37 UTC (rev 1210) @@ -45,9 +45,9 @@ private JButton runButton, stopButton, treeButton; private JTextArea infoArea; private Config config; - //private StartGUI startGUI; + private StartGUI startGUI; - private ThreadRun thread; + private long algorithmStartTime = 0; private GridBagLayout gridbag = new GridBagLayout(); private GridBagConstraints constraints = new GridBagConstraints(); @@ -67,16 +67,19 @@ private JLabel[] time = new JLabel[5]; private JLabel[] percent = new JLabel[5]; + + RunPanel(Config config, StartGUI startGUI) { super(new BorderLayout()); this.config = config; - //this.startGUI = startGUI; + this.startGUI = startGUI; runButton = new JButton("Run"); runButton.addActionListener(this); showPanel.add(runButton); stopButton = new JButton("Stop"); + stopButton.setEnabled(false); stopButton.addActionListener(this); showPanel.add(stopButton); treeButton = new JButton("Tree"); @@ -147,17 +150,35 @@ public void actionPerformed(ActionEvent e) { // start - if (e.getSource() == runButton && config.getLearningAlgorithm() != null - && !config.getThreadIsRunning()) { - thread = new ThreadRun(config); + if (e.getSource() == runButton) { + + // separate thread for learning algorithm + Thread algorithmThread = new Thread() { + @Override + public void run() { + setPriority(Thread.MIN_PRIORITY); + config.getLearningAlgorithm().start(); + } + }; + config.getReasoningService().resetStatistics(); - thread.start(); - ThreadStatistics threadStatistics = new ThreadStatistics(config, this); + algorithmThread.start(); + algorithmStartTime = System.nanoTime(); + StatisticsThread threadStatistics = new StatisticsThread(config, this); threadStatistics.start(); + runButton.setEnabled(false); + stopButton.setEnabled(true); + // disable other panes (we do not want changes while + // algorithm is running) + startGUI.disableTabbedPane(); } // stop - if (e.getSource() == stopButton && config.getLearningAlgorithm() != null) { - thread.exit(); + if (e.getSource() == stopButton) { + config.getLearningAlgorithm().stop(); + runButton.setEnabled(true); + stopButton.setEnabled(false); + // enable panels + startGUI.enableTabbedPane(); } // tree if (e.getSource() == treeButton) { @@ -170,12 +191,11 @@ * Show Statistics. */ public void showStats() { - System.out.println("stat update " + System.currentTimeMillis()); - Long algorithmRunTime = null; - Long overallReasoningTime = null; - Long instanceCheckReasoningTime = null; - Long retrievalReasoningTime = null; - Long subsumptionReasoningTime = null; +// System.out.println("stat update " + System.currentTimeMillis()); + long overallReasoningTime = 0; // = null; + long instanceCheckReasoningTime = 0; // = null; + long retrievalReasoningTime = 0; // = null; + long subsumptionReasoningTime = 0; // = null; infoArea.setText(""); // best solutions @@ -189,19 +209,18 @@ // + config.getLearningAlgorithm().getSolutionScore().toString() // + "\n\n"); - // reasoner statistics - if (config.getAlgorithmRunTime() != null) { - algorithmRunTime = config.getAlgorithmRunTime(); - bar[0].update(1.0); - time[0].setText(makeTime(algorithmRunTime)); - percent[0].setText("100%"); - } - if (config.getReasoningService() != null) { + // update algorith runtime + long algorithmRunTime = System.nanoTime() - algorithmStartTime; + bar[0].update(1.0); + time[0].setText(makeTime(algorithmRunTime)); + percent[0].setText("100%"); + + // update overall reasoning time overallReasoningTime = config.getReasoningService().getOverallReasoningTimeNs(); bar[1].update((double) overallReasoningTime / (double) algorithmRunTime); time[1].setText(makeTime(overallReasoningTime)); percent[1].setText(Percent(overallReasoningTime, algorithmRunTime)); - } + if (config.getReasoningService().getNrOfInstanceChecks() > 0) { instanceCheckReasoningTime = config.getReasoningService() .getInstanceCheckReasoningTimeNs(); Copied: trunk/src/dl-learner/org/dllearner/gui/StatisticsThread.java (from rev 1208, trunk/src/dl-learner/org/dllearner/gui/ThreadStatistics.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StatisticsThread.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/StatisticsThread.java 2008-09-15 11:19:37 UTC (rev 1210) @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.gui; + +/** + * This thread is responsible for sending update events to the GUI. + * In regular intervals it tests whether the learning algorithm is + * running and calls methods to update the statistics in the run + * panel. + * + * @author Tilo Hielscher + * @author Jens Lehmann + */ +public class StatisticsThread extends Thread { + + private Config config; + private RunPanel runPanel; + + public StatisticsThread(Config config, RunPanel runPanel) { + this.config = config; + this.runPanel = runPanel; + } + + /** + * Calls {@link RunPanel#showStats()} in regular intervals. + */ + @Override + public void run() { + try { + // initial delay of one second + sleep(1000); + while (config.getLearningAlgorithm().isRunning()) { + // update statistics every 3 seconds + runPanel.showStats(); + sleep(3000); + } + // show final stats + runPanel.showStats(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } +} Deleted: trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java 2008-09-15 09:20:10 UTC (rev 1209) +++ trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java 2008-09-15 11:19:37 UTC (rev 1210) @@ -1,58 +0,0 @@ -package org.dllearner.gui; - -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/** - * Start algorithm in a new thread. - * - * @author Tilo Hielscher - */ -public class ThreadRun extends Thread { - - Config config; - - public ThreadRun(Config config) { - this.config = config; - } - - /** - * method to start thread - */ - @Override - public void run() { - if (config.getLearningAlgorithm() != null) { - config.setThreadIsRunning(true); - this.setPriority(Thread.MIN_PRIORITY); - config.getLearningAlgorithm().start(); - config.setThreadIsRunning(false); - } - } - - /** - * stop thread - */ - public void exit() { - if (config.getLearningAlgorithm() != null) - config.getLearningAlgorithm().stop(); - config.setThreadIsRunning(false); - System.out.println("stop run"); - } -} Deleted: trunk/src/dl-learner/org/dllearner/gui/ThreadStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ThreadStatistics.java 2008-09-15 09:20:10 UTC (rev 1209) +++ trunk/src/dl-learner/org/dllearner/gui/ThreadStatistics.java 2008-09-15 11:19:37 UTC (rev 1210) @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.gui; - -/** - * Start statistics in a new thread. - * - * @author Tilo Hielscher - */ -public class ThreadStatistics extends Thread { - - private Config config; - private RunPanel runPanel; - - public ThreadStatistics(Config config, RunPanel runPanel) { - this.config = config; - this.runPanel = runPanel; - } - - /** - * method to start thread - */ - @Override - public void run() { - //this.setPriority(4); - if (config.getThreadIsRunning()) { - try { - sleep(1000); // sleep 1 second - } catch (InterruptedException e) { - e.printStackTrace(); - } - while (config.getThreadIsRunning()) { - try { - runPanel.showStats(); - sleep(3000); // sleep 3 seconds - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - runPanel.showStats(); - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |