I have a quite special problem and it is hard to break it down to a few lines of code and a few sentences but I will try to do so.
I am currently working on a software for real time optimization for alarms in process plants. The software receives new alarms from a server every time new alarms appear. Several of these alarms have the same root cause and my software analyses these alarms and groups them if they are related to each other.
My problem is comparing new alarms with old ones. I store the old alarms in a global list and append new alarms to this list when they appear.
The new alarms have to be analyzed whether they can be grouped with themselves and with the old alarms. The old alarms don’t need to be regrouped again.
As an example I have three old (o) alarms and three new ones (n).
The list will look like o1 o2 o3 n1 n2 n3. Now n1 has to be compared to o1, o2, o3, n2 and n3. n2 has to be compared to o1,o2,o3 and n3 and so on.
I used the following code to do this:
List<ALARM_ITEM> puffer = new List<ALARM_ITEM>();
puffer.AddRange(localOldAlarmList);
puffer.AddRange(localNewAlarmList);
localMergedList = puffer;
int mainListCounter = localOldAlarmList.Count;
for (; mainListCounter < localMergedList.Count; mainListCounter++)
{
/*if there are new elements just these elemnts will be used as static items*/
ALARM_ITEM staticAlarmItem = localMergedList[mainListCounter];
for (int j = -1; j <= 1; j += 2)
{
if (j < 0)
counterRunner = localOldAlarmListLength - 1;
else
counterRunner = mainListCounter + 1;
//Check against any ALARM_ITEM in timeframe
bool inTimeframe = true;
while (inTimeframe)
{
if ((counterRunner >= localMergedList.Count) || (counterRunner) < 0)
break;
ALARM_ITEM groupCandidate = new ALARM_ITEM();
groupCandidate = localMergedList[counterRunner];
//... several if clauses
MergeTwoAlarmGroups(staticAlarmItem, groupCandidate);
if (j < 0)
counterRunner -= 1;
else
counterRunner += 1;
}
}
}
Now what shall I say… I modified this approach working about 36 working hours now but still the software does just compare new alarms between each other and does not link it to the old alarms. The grouping algorithm is several pages long and I tried to break it down as far as I can. If anyone can give me an advice what I’m doing wrong I would be really glad because I’m getting mad over this problem. It’s the first time I’m really stuck in this project and I’m programming this software for more than three month now.
Kind regards
Larimow
I don’t fully understand your algorithm. I would use a
as the data structure, where the values are groups of events and the keys are representatives of each group. When a new alarm
aarrives, the algorithm would bek, check whetherais grouped withkkand breakvaluescontaining justa, and add(a, values)to the dictionaryIn other words, you store the groups of alarm in a dict whose keys are “representative” alarms for the groups. To add a new alarm, you only have to compare it against the representative alarms.
This assumes that if
agroups withbandbgroups withcthenagroups withc. If that is not the case, there isn’t necessarily a consistent way of grouping the alarms. And if it is the case then the grouping relation is an equivalence, so the algorithm will work.