From 686f3140f3bc7e9ed469c281876fb0af91b207c8 Mon Sep 17 00:00:00 2001
From: L <letitia.li@telecom-paristech.fr>
Date: Tue, 18 Sep 2018 07:57:54 -0400
Subject: [PATCH] Updated latency calculation

---
 src/main/java/ui/GTMLModeling.java                  |  8 +++++---
 .../JFrameAvatarInteractiveSimulation.java          | 13 ++++++++++++-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/main/java/ui/GTMLModeling.java b/src/main/java/ui/GTMLModeling.java
index f3d8a5b441..0aa80a490b 100755
--- a/src/main/java/ui/GTMLModeling.java
+++ b/src/main/java/ui/GTMLModeling.java
@@ -970,9 +970,7 @@ public class GTMLModeling {
                                     tt2 = tmlm.getTMLTaskByName(makeName(port2, port2.getFather().getValue()));
                                     channel.setTasks(tt1, tt2);
 
-                                    if (port1.isLossy()) {
-                                        channel.setLossy(true, port1.getLossPercentage(), port1.getMaxNbOfLoss());
-                                    }
+
 
                                     // Complex channels are used only for transformation towards the simulator
                                     TMLPort tmlport1, tmlport2;
@@ -985,6 +983,10 @@ public class GTMLModeling {
                                     tmlport2.setPostex(port2.isPostex());
                                     tmlport2.setAssociatedEvent(port2.getAssociatedEvent());
                                     channel.setPorts(tmlport1, tmlport2);
+
+                                    if (port1.isLossy()) {
+                                        channel.setLossy(true, port1.getLossPercentage(), port1.getMaxNbOfLoss());
+                                    }
                                     tmlm.addChannel(channel);
                                     listE.addCor(channel, tgc);
                                     //TraceManager.addDev("Adding channel " + channel.getName());
diff --git a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java
index 88098c5904..de6790d811 100755
--- a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java
+++ b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java
@@ -1536,30 +1536,41 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
                 }
             }
             //  
+
             for (String st1 : transTimes.keySet()) {
                 for (String st2 : transTimes.keySet()) {
                     if (st1 != st2 && nameLatencyMap.containsKey(st1 + "--" + st2)) {
                         SimulationLatency sl = nameLatencyMap.get(st1 + "--" + st2);
                         if (transTimes.get(st1) != null && transTimes.get(st2) != null) {
+
+							List<String> tmptimes2 = new ArrayList<>(transTimes.get(st2));
+
                             ArrayList<Integer> minTimes = new ArrayList<Integer>();
                             /*SimulationLatency sl = new SimulationLatency();
                               sl.setTransaction1(st1);
                               sl.setTransaction2(st2);*/
+		
+						
                             for (String time1 : transTimes.get(st1)) {
+								String match = "";
                                 //Find the first subsequent transaction
                                 int time = Integer.MAX_VALUE;
-                                for (String time2 : transTimes.get(st2)) {
+                                for (String time2 : tmptimes2) {
+								
                                     int diff = Integer.valueOf(time2) - Integer.valueOf(time1);
                                     if (diff < time && diff >= 0) {
                                         time = diff;
+										match = time2;
                                     }
                                 }
+								tmptimes2.remove(match);
                                 if (time != Integer.MAX_VALUE) {
                                     minTimes.add(time);
                                 }
                             }
                             //  
                             if (minTimes.size() > 0) {
+
                                 int sum = 0;
                                 sl.setMinTime(Integer.toString(Collections.min(minTimes)));
                                 sl.setMaxTime(Integer.toString(Collections.max(minTimes)));
-- 
GitLab