Skip to content

Commit 5fe34fc

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
install default SCPN for first start
1 parent cdde7de commit 5fe34fc

File tree

3 files changed

+125
-49
lines changed

3 files changed

+125
-49
lines changed

TimeNETOptimizationEnvironment/src/toe/MainFrame.java

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ public MainFrame() throws IOException {
109109
// Exception bearbeiten
110110
}
111111

112+
//Install default scpn file
113+
File defaultSCPN = new File(support.NAME_OF_DEFAULT_SCPN);
114+
if (!defaultSCPN.exists() || !defaultSCPN.isFile()) {
115+
try {
116+
InputStream ddlStream = this.getClass().getClassLoader().getResourceAsStream("toe/default_SCPN.xml");
117+
FileOutputStream fos = null;
118+
try {
119+
fos = new FileOutputStream(support.NAME_OF_DEFAULT_SCPN);
120+
byte[] buf = new byte[2048];
121+
int r = ddlStream.read(buf);
122+
while (r != -1) {
123+
fos.write(buf, 0, r);
124+
r = ddlStream.read(buf);
125+
}
126+
} finally {
127+
if (fos != null) {
128+
fos.close();
129+
}
130+
}
131+
} catch (IOException e) {
132+
support.log("Failed to install default SCPN", typeOfLogLevel.ERROR);
133+
}
134+
}
135+
112136
jButtonPathToTimeNet.setBackground(Color.GRAY);
113137
jButtonPathToTimeNet.setText("Enter Path To TimeNet");
114138

@@ -121,7 +145,7 @@ public MainFrame() throws IOException {
121145
pMaxTime.initWithValues("MaxTime", 0, 0, 1);
122146
pMaxError.initWithValues("MaxError", 5, 5, 1);
123147

124-
this.jTextFieldSCPNFile.setText(auto.getProperty("file"));
148+
this.jTextFieldSCPNFile.setText(auto.getProperty("file", support.NAME_OF_DEFAULT_SCPN));
125149
//this.jTextFieldPathToTimeNet.setText(auto.getProperty("timenetpath"));
126150
this.setPathToTimeNet(auto.getProperty("timenetpath", ""));
127151
//support.log("Read Path to TimeNet:"+auto.getProperty("timenetpath"));
@@ -1077,48 +1101,46 @@ private void jButtonStartOptimizationActionPerformed(java.awt.event.ActionEvent
10771101
if (this.sizeOfDesignSpace <= support.DEFAULT_MINIMUM_DESIGNSPACE_FOR_OPTIMIZATION) {
10781102
support.log("Design space to small, no Optimization posible.", typeOfLogLevel.INFO);
10791103
support.setStatusText("Designspace to small for Opti.");
1080-
} else {
1081-
if (this.getListOfActiveMeasureMentsToOptimize().size() >= 1) {
1082-
this.switchUIState(uiState.processRunning);
1083-
//Ask for Tmp-Path
1084-
String tPath = (support.getPathToDirByDialog("Dir for export TMP-Files and log.\n ", support.getTmpPath()));
1085-
//if tmpPath is empty or null --> return
1086-
if (tPath != null) {
1087-
support.setTmpPath(tPath);
1088-
this.saveProperties();
1089-
support.setPathToTimeNet(pathToTimeNet);
1090-
support.setMainFrame(this);
1091-
support.setOriginalFilename(fileName);
1092-
support.setStatusLabel(jLabelExportStatus);
1093-
support.setMeasureFormPane(jTabbedPaneOptiTargets);
1094-
//support.setTypeOfStartValue((typeOfStartValueEnum)support.getOptimizerPreferences().jComboBoxTypeOfStartValue.getSelectedItem());
1095-
1096-
//If Parameterbase is null -->eject
1097-
if (support.getParameterBase() == null) {
1098-
support.setStatusText("No Paramaterbase set.");
1099-
support.log("No Paramaterbase set. No Simulation possible.", typeOfLogLevel.INFO);
1100-
this.popUIState();
1101-
return;
1102-
}
1103-
//Remove all old Optimizationstatistics
1104-
StatisticAggregator.removeOldOptimizationsFromList();
1105-
1106-
//Save original Parameterset, for stepping and designspace borders
1107-
support.setOriginalParameterBase(support.getCopyOfParameterSet(support.getParameterBase()));
1108-
//start Optimization via extra method, set number of multiple optimizations before
1109-
support.setNumberOfOptiRunsToGo((Integer) this.jSpinnerNumberOfOptimizationRuns.getValue());
1110-
support.getOptimizerPreferences().setNumberOfActualOptimizationAnalysis(0);
1111-
startOptimizationAgain();
1112-
1113-
} else {
1114-
support.log("No Tmp-Path given, Optimization not possible.", typeOfLogLevel.ERROR);
1104+
} else if (this.getListOfActiveMeasureMentsToOptimize().size() >= 1) {
1105+
this.switchUIState(uiState.processRunning);
1106+
//Ask for Tmp-Path
1107+
String tPath = (support.getPathToDirByDialog("Dir for export TMP-Files and log.\n ", support.getTmpPath()));
1108+
//if tmpPath is empty or null --> return
1109+
if (tPath != null) {
1110+
support.setTmpPath(tPath);
1111+
this.saveProperties();
1112+
support.setPathToTimeNet(pathToTimeNet);
1113+
support.setMainFrame(this);
1114+
support.setOriginalFilename(fileName);
1115+
support.setStatusLabel(jLabelExportStatus);
1116+
support.setMeasureFormPane(jTabbedPaneOptiTargets);
1117+
//support.setTypeOfStartValue((typeOfStartValueEnum)support.getOptimizerPreferences().jComboBoxTypeOfStartValue.getSelectedItem());
1118+
1119+
//If Parameterbase is null -->eject
1120+
if (support.getParameterBase() == null) {
1121+
support.setStatusText("No Paramaterbase set.");
1122+
support.log("No Paramaterbase set. No Simulation possible.", typeOfLogLevel.INFO);
11151123
this.popUIState();
1124+
return;
11161125
}
1126+
//Remove all old Optimizationstatistics
1127+
StatisticAggregator.removeOldOptimizationsFromList();
1128+
1129+
//Save original Parameterset, for stepping and designspace borders
1130+
support.setOriginalParameterBase(support.getCopyOfParameterSet(support.getParameterBase()));
1131+
//start Optimization via extra method, set number of multiple optimizations before
1132+
support.setNumberOfOptiRunsToGo((Integer) this.jSpinnerNumberOfOptimizationRuns.getValue());
1133+
support.getOptimizerPreferences().setNumberOfActualOptimizationAnalysis(0);
1134+
startOptimizationAgain();
11171135

11181136
} else {
1119-
support.log("No Measurements to optimize for are chosen.", typeOfLogLevel.INFO);
1120-
support.setStatusText("No Measurements chosen. No Opti possible.");
1137+
support.log("No Tmp-Path given, Optimization not possible.", typeOfLogLevel.ERROR);
1138+
this.popUIState();
11211139
}
1140+
1141+
} else {
1142+
support.log("No Measurements to optimize for are chosen.", typeOfLogLevel.INFO);
1143+
support.setStatusText("No Measurements chosen. No Opti possible.");
11221144
}
11231145
}//GEN-LAST:event_jButtonStartOptimizationActionPerformed
11241146

@@ -1421,7 +1443,7 @@ private void jProgressBarMemoryUsageMouseClicked(java.awt.event.MouseEvent evt)
14211443
* @param evt Event from mouseclick
14221444
*/
14231445
private void jCheckBoxSlaveSimulatorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jCheckBoxSlaveSimulatorMouseClicked
1424-
//set Property for startup
1446+
//set Property for startup
14251447
//start the Slave-Thread
14261448

14271449
//If is selected and will be unselected then stop thread
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<net id="0" netclass="SCPN"
3+
xmlns="http://pdv.cs.tu-berlin.de/TimeNET/schema/SCPN"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pdv.cs.tu-berlin.de/TimeNET/schema/SCPN etc/schemas/SCPN.xsd">
5+
<place capacity="0" id="0.0" queue="FIFO" tokentype="bool" type="node" watch="false">
6+
<graphics orientation="0" x="198" y="69"/>
7+
<label id="0.0.0" text="P" type="text">
8+
<graphics x="-10" y="-40"/>
9+
</label>
10+
</place>
11+
<timedTransition id="0.1" serverType="ExclusiveServer"
12+
specType="Automatic" takeFirst="false"
13+
timeFunction="EXP(1.0/$Tsource)" type="node" watch="false">
14+
<graphics orientation="0" x="58" y="69"/>
15+
<label id="0.1.0" text="Source" type="text">
16+
<graphics x="-10" y="-40"/>
17+
</label>
18+
</timedTransition>
19+
<timedTransition globalGuard="#P>30" id="0.2"
20+
serverType="ExclusiveServer" specType="Automatic" takeFirst="true"
21+
timeFunction="EXP(1.0/$Tdrain)" type="node" watch="false">
22+
<graphics orientation="0" x="338" y="69"/>
23+
<label id="0.2.0" text="Drain" type="text">
24+
<graphics x="-10" y="-40"/>
25+
</label>
26+
</timedTransition>
27+
<immediateTransition globalGuard="#P>70" id="0.6" priority="1"
28+
serverType="ExclusiveServer" specType="Automatic" takeFirst="false"
29+
type="node" watch="false" weight="1.0E0">
30+
<graphics orientation="-90" x="199" y="157"/>
31+
<label id="0.6.0" text="T0" type="text">
32+
<graphics x="32" y="-10"/>
33+
</label>
34+
</immediateTransition>
35+
<arc fromNode="0.1" id="0.3" toNode="0.0" type="connector">
36+
<inscription id="0.3.0" text="new(true)" type="inscriptionText">
37+
<graphics x="-30" y="0"/>
38+
</inscription>
39+
</arc>
40+
<arc fromNode="0.0" id="0.4" toNode="0.2" type="connector">
41+
<inscription id="0.4.0" text="x" type="inscriptionText">
42+
<graphics x="0" y="0"/>
43+
</inscription>
44+
</arc>
45+
<arc fromNode="0.0" id="0.7" toNode="0.6" type="connector">
46+
<inscription id="0.7.0" text="x" type="inscriptionText">
47+
<graphics x="0" y="0"/>
48+
</inscription>
49+
</arc>
50+
<measure eval="TimeAverage"
51+
expression="1-((40&lt;=#P)&amp;&amp;(50>=#P))" id="0.5"
52+
name="MeasureP" result="0.6408965" type="text" watch="true">
53+
<graphics x="50" y="210"/>
54+
</measure>
55+
<parameter dataType="real" defaultValue="50" description="" name="Tdrain"/>
56+
<parameter dataType="real" defaultValue="50" description="" name="Tsource"/>
57+
</net>

TimeNETOptimizationEnvironment/src/toe/support.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public class support {
116116
public static final String NAME_OF_LOGFILE = NAME_OF_PREF_DIR + "TimeNETLogFile.log";//the name of the program logfile, if logging to file is active
117117
public static final String NAME_OF_PREFERENCES_FILE = NAME_OF_PREF_DIR + "ApplicationPreferences.prop";//name of the pref-file for program-wide prefs
118118
public static final String NAME_OF_OPTIMIZER_PREFFERENCES_FILE = NAME_OF_PREF_DIR + "OptimizerPreferences.prop";//name of the pref file for optimization parameters
119+
public static final String NAME_OF_DEFAULT_SCPN = NAME_OF_PREF_DIR + "default_SCPN.xml";//name of default scpn to be loaded at first start
119120

120121
public static final boolean DEFAULT_LOG_TO_WINDOW = true;
121122
public static final boolean DEFAULT_LOG_TO_FILE = false;
@@ -622,7 +623,7 @@ public static void addLinesToLogFileFromListOfParser(ArrayList<SimulationType> p
622623
dummyParameterForCPUTime.setEndValue(0.0);
623624

624625
try {
625-
//support.log("Number of Simulationtypes to add is "+pList.size());
626+
//support.log("Number of Simulationtypes to add is "+pList.size());
626627

627628
//Check if list is null, then exit
628629
if (pList == null) {
@@ -706,7 +707,7 @@ public static void addLinesToLogFileFromListOfSimulationBatchesIncludingNumRuns(
706707
dummyParameterForCPUTime.setEndValue(0.0);
707708

708709
try {
709-
//support.log("Number of Simulationtypes to add is "+pList.size());
710+
//support.log("Number of Simulationtypes to add is "+pList.size());
710711

711712
//Check if list is null, then exit
712713
if (pList == null) {
@@ -1202,14 +1203,10 @@ public static void printOptimizedMeasures(SimulationType p, ArrayList<MeasureTyp
12021203
activeMeasure.setTargetValue(activeMeasureFromInterface.getTargetValue(), activeMeasureFromInterface.getTargetTypeOf());
12031204
if (activeMeasure.getTargetTypeOf().equals(typedef.typeOfTarget.value)) {
12041205
distance = activeMeasure.getDistanceFromTarget();
1205-
} else {
1206-
if (activeMeasure.getTargetTypeOf().equals(typedef.typeOfTarget.min)) {
1207-
distance = activeMeasure.getMeanValue();
1208-
} else {
1209-
if (activeMeasure.getTargetTypeOf().equals(typedef.typeOfTarget.max)) {
1210-
distance = 0 - activeMeasure.getMeanValue();
1211-
}
1212-
}
1206+
} else if (activeMeasure.getTargetTypeOf().equals(typedef.typeOfTarget.min)) {
1207+
distance = activeMeasure.getMeanValue();
1208+
} else if (activeMeasure.getTargetTypeOf().equals(typedef.typeOfTarget.max)) {
1209+
distance = 0 - activeMeasure.getMeanValue();
12131210
}
12141211
support.printMeasureType(activeMeasure, "**** Optimized Value for Measure is ****", "---------------------------");
12151212
}

0 commit comments

Comments
 (0)