diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/objectives/TrajectoryFitness.java')
-rw-r--r-- | Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/objectives/TrajectoryFitness.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/objectives/TrajectoryFitness.java b/Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/objectives/TrajectoryFitness.java new file mode 100644 index 00000000..f783afac --- /dev/null +++ b/Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/objectives/TrajectoryFitness.java | |||
@@ -0,0 +1,84 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Andras Szabolcs Nagy, Abel Hegedus, Akos Horvath, Zoltan Ujhelyi and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package org.eclipse.viatra.dse.objectives; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | |||
14 | import org.eclipse.viatra.dse.designspace.api.TrajectoryInfo; | ||
15 | |||
16 | /** | ||
17 | * This class represents a trajectory and its fitness. | ||
18 | * @author Andras Szabolcs Nagy | ||
19 | * | ||
20 | */ | ||
21 | public class TrajectoryFitness { | ||
22 | |||
23 | public Object[] trajectory; | ||
24 | public Fitness fitness; | ||
25 | |||
26 | public int rank; | ||
27 | public double crowdingDistance; | ||
28 | |||
29 | private int hash; | ||
30 | |||
31 | public int survive; | ||
32 | |||
33 | /** | ||
34 | * Creates a {@link TrajectoryFitness} with the full trajectory. | ||
35 | * @param trajectory The trajectory. | ||
36 | * @param fitness The fitness. | ||
37 | */ | ||
38 | public TrajectoryFitness(Object[] trajectory, Fitness fitness) { | ||
39 | this.fitness = fitness; | ||
40 | this.trajectory = trajectory; | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Creates a {@link TrajectoryFitness} with the full trajectory. | ||
45 | * @param trajectoryInfo The trajectory. | ||
46 | * @param fitness The fitness. | ||
47 | */ | ||
48 | public TrajectoryFitness(TrajectoryInfo trajectoryInfo, Fitness fitness) { | ||
49 | this.fitness = fitness; | ||
50 | List<Object> fullTraj = trajectoryInfo.getTrajectory(); | ||
51 | trajectory = fullTraj.toArray(new Object[fullTraj.size()]); | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * Creates a {@link TrajectoryFitness} with the given activation id} | ||
56 | * @param transition The transition. | ||
57 | * @param fitness The fitness. | ||
58 | */ | ||
59 | public TrajectoryFitness(Object transition, Fitness fitness) { | ||
60 | this.fitness = fitness; | ||
61 | trajectory = new Object[] {transition}; | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | public boolean equals(Object obj) { | ||
66 | if (obj instanceof TrajectoryFitness) { | ||
67 | return Arrays.equals(trajectory, ((TrajectoryFitness) obj).trajectory); | ||
68 | } | ||
69 | return false; | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | public int hashCode() { | ||
74 | if (hash == 0 && trajectory.length > 0) { | ||
75 | hash = Arrays.hashCode(trajectory); | ||
76 | } | ||
77 | return hash; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public String toString() { | ||
82 | return Arrays.toString(trajectory) + fitness.toString(); | ||
83 | } | ||
84 | } | ||