Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a92b260

Browse filesBrowse files
committed
Graphical log pane & new LAF
- New Look and Feel (faster and better-looking) - Graphical logs - No "verbose" log option anymore ("on" by default in text mode) - Fixed glitches with GUI and task execution
1 parent 0434e4c commit a92b260
Copy full SHA for a92b260

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

42 files changed

+665
-265
lines changed

‎src/main/java/pulse/math/ParameterIdentifier.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/math/ParameterIdentifier.java
+22-9Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package pulse.math;
22

3+
import java.util.Objects;
34
import pulse.properties.NumericPropertyKeyword;
45

56
public class ParameterIdentifier {
@@ -15,6 +16,14 @@ public ParameterIdentifier(NumericPropertyKeyword keyword, int index) {
1516
public ParameterIdentifier(NumericPropertyKeyword keyword) {
1617
this(keyword, 0);
1718
}
19+
20+
@Override
21+
public int hashCode() {
22+
int hash = 7;
23+
hash = 29 * hash + Objects.hashCode(this.keyword);
24+
hash = 29 * hash + this.index;
25+
return hash;
26+
}
1827

1928
public ParameterIdentifier(int index) {
2029
this.index = index;
@@ -30,24 +39,28 @@ public int getIndex() {
3039

3140
@Override
3241
public boolean equals(Object id) {
33-
if(!id.getClass().equals(ParameterIdentifier.class)) {
42+
if(id.getClass() == null) {
3443
return false;
3544
}
3645

37-
var pid = (ParameterIdentifier) id;
38-
39-
boolean result = true;
46+
var classA = id.getClass();
47+
var classB = this.getClass();
4048

41-
if(keyword != pid.keyword || index != pid.index)
42-
result = false;
43-
44-
return result;
49+
if(classA != classB) {
50+
return false;
51+
}
4552

53+
var pid = (ParameterIdentifier) id;
54+
return keyword == pid.keyword && Math.abs(index - pid.index) < 1;
4655
}
4756

4857
@Override
4958
public String toString() {
50-
return keyword + " # " + index;
59+
StringBuilder sb = new StringBuilder("").append(keyword);
60+
if(index > 0) {
61+
sb.append(" # ").append(index);
62+
}
63+
return sb.toString();
5164
}
5265

5366
}

‎src/main/java/pulse/properties/NumericPropertyKeyword.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/properties/NumericPropertyKeyword.java
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,13 @@ public enum NumericPropertyKeyword {
390390
* Heat loss for the gas in the 2T-model.
391391
*/
392392

393-
HEAT_LOSS_GAS;
393+
HEAT_LOSS_GAS,
394+
395+
/**
396+
* Value of objective function.
397+
*/
398+
399+
OBJECTIVE_FUNCTION;
394400

395401
public static Optional<NumericPropertyKeyword> findAny(String key) {
396402
return Arrays.asList(values()).stream().filter(keys -> keys.toString().equalsIgnoreCase(key)).findAny();

‎src/main/java/pulse/search/GeneralTask.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/search/GeneralTask.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public GeneralTask() {
6464
@Override
6565
public void run() {
6666
setDefaultOptimiser();
67+
best = null;
6768
setIterativeState( optimiser.initState(this) );
6869

6970
var errorTolerance = (double) optimiser.getErrorTolerance().getValue();

‎src/main/java/pulse/search/direction/ComplexPath.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/search/direction/ComplexPath.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import pulse.math.linear.SquareMatrix;
66
import pulse.search.GeneralTask;
7-
import pulse.tasks.SearchTask;
87

98
/**
109
* <p>

‎src/main/java/pulse/search/direction/CompositePathOptimiser.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/search/direction/CompositePathOptimiser.java
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public boolean iteration(GeneralTask task) throws SolverException {
6161
} else {
6262

6363
double initialCost = task.getResponse().objectiveFunction(task);
64+
p.setCost(initialCost);
6465
var parameters = task.searchVector();
6566

6667
p.setParameters(parameters); // store current parameters
@@ -94,6 +95,7 @@ public boolean iteration(GeneralTask task) throws SolverException {
9495
task.storeState();
9596
p.resetFailedAttempts();
9697
this.prepare(task); // update gradients, Hessians, etc. -> for the next step, [k + 1]
98+
p.setCost(newCost);
9799
p.incrementStep(); // increment the counter of successful steps
98100
}
99101

@@ -142,4 +144,4 @@ public GradientGuidedPath initState(GeneralTask t) {
142144
return new ComplexPath(t);
143145
}
144146

145-
}
147+
}

‎src/main/java/pulse/search/direction/IterativeState.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/search/direction/IterativeState.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void setCost(double cost) {
4141

4242
public void reset() {
4343
iteration = 0;
44+
setCost(Double.POSITIVE_INFINITY);
4445
}
4546

4647
public NumericProperty getIteration() {

‎src/main/java/pulse/search/direction/LMOptimiser.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/search/direction/LMOptimiser.java
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public boolean iteration(GeneralTask task) throws SolverException {
6969
} else {
7070

7171
double initialCost = task.objectiveFunction();
72+
p.setCost(initialCost);
7273
var parameters = task.searchVector();
7374

7475
p.setParameters(parameters); // store current parameters
@@ -88,7 +89,7 @@ public boolean iteration(GeneralTask task) throws SolverException {
8889
parameters, candidate)); // assign new parameters
8990

9091
double newCost = task.objectiveFunction(); // calculate the sum of squared residuals
91-
92+
9293
/*
9394
* Delayed gratification
9495
*/
@@ -103,6 +104,7 @@ public boolean iteration(GeneralTask task) throws SolverException {
103104
p.resetFailedAttempts();
104105
p.setLambda(p.getLambda() / 3.0);
105106
p.setComputeJacobian(false);
107+
p.setCost(newCost);
106108
p.incrementStep(); // increment the counter of successful steps
107109
}
108110

‎src/main/java/pulse/search/direction/pso/ParticleSwarmOptimiser.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/search/direction/pso/ParticleSwarmOptimiser.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public boolean iteration(GeneralTask task) throws SolverException {
4646
swarmState.incrementStep();
4747

4848
task.assign(swarmState.getBestSoFar().getPosition());
49-
task.objectiveFunction();
49+
double cost = task.objectiveFunction();
50+
swarmState.setCost(cost);
5051

5152
return true;
5253
}

‎src/main/java/pulse/tasks/Calculation.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/tasks/Calculation.java
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import pulse.util.InstanceDescriptor;
3535
import pulse.util.PropertyEvent;
3636
import pulse.util.PropertyHolder;
37+
import pulse.util.UpwardsNavigable;
3738

3839
public class Calculation extends PropertyHolder implements Comparable<Calculation>, Response {
3940

@@ -78,14 +79,14 @@ public Calculation(Calculation c) {
7879
instanceDescriptor.addListener(() -> initModelCriterion(rs));
7980
}
8081

81-
public void assumeOwnership() {
82-
problem.setParent(this);
83-
scheme.setParent(this);
84-
rs.setParent(this);
85-
os.setParent(this);
86-
result.setParent(this);
82+
public void conformTo(UpwardsNavigable owner) {
83+
problem.setParent(owner);
84+
scheme.setParent(owner);
85+
rs.setParent(owner);
86+
os.setParent(owner);
87+
result.setParent(owner);
8788
}
88-
89+
8990
public void clear() {
9091
this.status = INCOMPLETE;
9192
this.problem = null;

‎src/main/java/pulse/tasks/SearchTask.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/tasks/SearchTask.java
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ public void run() {
280280
}
281281

282282
current.getProblem().parameterListChanged(); // get updated list of parameters
283-
setDefaultOptimiser();
284-
283+
285284
super.run();
286285
}
287286

@@ -333,9 +332,11 @@ public void storeCalculation() {
333332
}
334333

335334
public void switchTo(Calculation calc) {
335+
current.setParent(null);
336+
current.conformTo(null);
336337
current = new Calculation(calc);
337-
current.assumeOwnership();
338338
current.setParent(this);
339+
calc.conformTo(calc);
339340
current.setStatus(Status.READY);
340341
var e = new TaskRepositoryEvent(TaskRepositoryEvent.State.TASK_MODEL_SWITCH, this.getIdentifier());
341342
fireRepositoryEvent(e);

‎src/main/java/pulse/tasks/logs/AbstractLogger.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/tasks/logs/AbstractLogger.java
+49-17Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
import static java.util.concurrent.Executors.newSingleThreadExecutor;
55
import javax.swing.JComponent;
66
import pulse.tasks.TaskManager;
7+
import static pulse.tasks.logs.Status.DONE;
78
import pulse.util.Descriptive;
89

910
public abstract class AbstractLogger implements Descriptive {
1011

11-
private final ExecutorService updateExecutor = newSingleThreadExecutor();
12-
12+
private final ExecutorService updateExecutor;
13+
14+
public AbstractLogger() {
15+
updateExecutor = newSingleThreadExecutor();
16+
}
17+
1318
public synchronized void update() {
1419
var task = TaskManager.getManagerInstance().getSelectedTask();
1520

@@ -19,32 +24,59 @@ public synchronized void update() {
1924

2025
var log = task.getLog();
2126

22-
if (!log.isStarted()) {
23-
return;
27+
if (log.isStarted()) {
28+
post(log.lastEntry());
2429
}
25-
26-
post(log.lastEntry());
30+
2731
}
28-
32+
2933
public ExecutorService getUpdateExecutor() {
3034
return updateExecutor;
3135
}
32-
36+
3337
public synchronized void callUpdate() {
3438
updateExecutor.submit(() -> update());
3539
}
36-
40+
41+
public void postAll() {
42+
clear();
43+
44+
var task = TaskManager.getManagerInstance().getSelectedTask();
45+
46+
if (task != null) {
47+
48+
var log = task.getLog();
49+
50+
if (log.isStarted()) {
51+
52+
log.getLogEntries().stream().forEach(entry -> post(entry));
53+
54+
if (task.getStatus() == DONE) {
55+
printTimeTaken(log);
56+
}
57+
58+
}
59+
60+
}
61+
62+
}
63+
64+
@Override
65+
public String describe() {
66+
var task = TaskManager.getManagerInstance().getSelectedTask();
67+
return "Log" + (task == null ? "" : "_" + task.getIdentifier().getValue());
68+
}
69+
3770
public abstract JComponent getGUIComponent();
71+
3872
public abstract void printTimeTaken(Log log);
73+
3974
public abstract void post(LogEntry logEntry);
75+
4076
public abstract void post(String text);
41-
public abstract void postAll();
77+
4278
public abstract void clear();
79+
4380
public abstract boolean isEmpty();
44-
45-
@Override
46-
public String describe() {
47-
return "Log_" + TaskManager.getManagerInstance().getSelectedTask().getIdentifier().getValue();
48-
}
49-
50-
}
81+
82+
}

‎src/main/java/pulse/tasks/logs/DataLogEntry.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/tasks/logs/DataLogEntry.java
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import java.lang.reflect.InvocationTargetException;
44
import java.util.List;
5-
import pulse.Response;
65
import pulse.math.Parameter;
76
import pulse.math.ParameterIdentifier;
87
import pulse.properties.NumericProperties;
8+
import static pulse.properties.NumericProperties.def;
9+
import static pulse.properties.NumericPropertyKeyword.OBJECTIVE_FUNCTION;
910

1011
import pulse.tasks.SearchTask;
1112
import pulse.tasks.TaskManager;
@@ -55,10 +56,19 @@ public DataLogEntry(SearchTask task) {
5556
private void fill() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
5657
var task = TaskManager.getManagerInstance().getTask(getIdentifier());
5758
entry = task.searchVector().getParameters();
59+
//iteration
5860
var pval = task.getIterativeState().getIteration();
5961
var pid = new Parameter(new ParameterIdentifier(pval.getType()));
60-
pid.setValue( (int) pval.getValue() );
62+
pid.setValue((int) pval.getValue());
63+
//cost
64+
var costId = new Parameter(new ParameterIdentifier(OBJECTIVE_FUNCTION));
65+
var costval = task.getIterativeState().getCost();
66+
//
6167
entry.add(0, pid);
68+
if (NumericProperties.isValueSensible(def(OBJECTIVE_FUNCTION), costval)) {
69+
costId.setValue(costval);
70+
entry.add(costId);
71+
}
6272
}
6373

6474
public List<Parameter> getData() {
@@ -91,15 +101,15 @@ public String toString() {
91101
var def = NumericProperties.def(p.getIdentifier().getKeyword());
92102
boolean b = def.getValue() instanceof Integer;
93103
Number val;
94-
if(b) {
104+
if (b) {
95105
val = (int) Math.rint(p.getApparentValue());
96-
} else{
106+
} else {
97107
val = p.getApparentValue();
98108
}
99109
def.setValue(val);
100110
sb.append(def.getAbbreviation(false));
101111
int index = p.getIdentifier().getIndex();
102-
if(index > 0) {
112+
if (index > 0) {
103113
sb.append(" - ").append(index);
104114
}
105115
sb.append("</td><<td>");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.