TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
UDCSTI.cs
Go to the documentation of this file.
1 // TraceLab Component Library
2 // Copyright © 2012-2013 SEMERU
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using TraceLabSDK.Types;
22 
23 namespace TraceLab.Components.DevelopmentKit.Postprocessors.CSTI
24 {
28  public static class UDCSTI
29  {
37  public static TLSimilarityMatrix Compute(TLSimilarityMatrix sims, TLSimilarityMatrix relationships, TLSimilarityMatrix feedback)
38  {
39  // new matrix
40  TLSimilarityMatrix newMatrix = new TLSimilarityMatrix();
41  // compute delta
42  double delta = DeltaUtils.Compute(sims);
43  // make sure the entire list is sorted
44  TLLinksList links = sims.AllLinks;
45  links.Sort();
46  // end condition
47  int correct = 0;
48  // iterate over each source-target pair
49  while (links.Count > 0 && correct < feedback.Count)
50  {
51  // get link at top of list
52  TLSingleLink link = links[0];
53  // check feedback
54  if (feedback.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
55  {
56  correct++;
57  // update related links
58  for (int i = 1; i < links.Count; i++)
59  {
60  if (link.SourceArtifactId.Equals(links[i].SourceArtifactId)
61  && relationships.IsLinkAboveThreshold(link.TargetArtifactId, links[i].TargetArtifactId))
62  {
63  links[i].Score += links[i].Score * delta;
64  }
65  }
66  }
67  // remove link
68  newMatrix.AddLink(link.SourceArtifactId, link.TargetArtifactId, link.Score);
69  links.RemoveAt(0);
70  // reorder links
71  links.Sort();
72  }
73  return newMatrix;
74  }
75  }
76 }