Index: branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/VariableInteractionNetwork.cs
===================================================================
--- branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/VariableInteractionNetwork.cs	(revision 16295)
+++ branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/VariableInteractionNetwork.cs	(revision 16497)
@@ -35,4 +35,78 @@
   [StorableClass]
   public class VariableInteractionNetwork : DirectedGraph {
+
+    /// <summary>
+    /// Creates a simple network from a matrix of variable impacts (each row represents a target variable, each column represents an input variable)
+    /// For each target variable not more than one row can be defined (no junction nodes are build, cf. FromNmseAndVariableImpacts(..) for building more complex networks).
+    /// The network is acyclic. Values in the diagonal are ignored.
+    /// The algorithm starts with an empty network and incrementally adds next most relevant input variable for each target variable up to a given threshold
+    /// In each iteration cycles are broken by removing the weakest link.
+    /// </summary>
+    /// <param name="nmse">vector of NMSE values for each target variable</param>
+    /// <param name="variableImpacts">Variable impacts (smaller is lower impact). Row names and columns names should be set</param>
+    /// <param name="nmseThreshold">Threshold for NMSE values. Variables with a NMSE value larger than the threshold are considered as independent variables</param>
+    /// <param name="varImpactThreshold">Threshold for variable impact values. Impacts with a value smaller than the threshold are considered as independent</param>
+    /// <returns></returns>
+    public static VariableInteractionNetwork CreateSimpleNetwork(double[] nmse, DoubleMatrix variableImpacts, double nmseThreshold = 0.2, double varImpactThreshold = 0.0) {
+      if (variableImpacts.Rows != variableImpacts.Columns) throw new ArgumentException();
+      var network = new VariableInteractionNetwork();
+      var targets = new Dictionary<string, double>();
+      string[] varNames = variableImpacts.RowNames.ToArray();
+      if (nmse.Length != varNames.Length) throw new ArgumentException();
+
+      for (int i = 0; i < varNames.Length; i++) {
+        var name = varNames[i];
+        var varVertex = new VariableNetworkNode() {Label = name, Weight = nmse[i]};
+        network.AddVertex(varVertex);
+        if (nmse[i] < nmseThreshold) {
+          targets.Add(name, nmse[i]);
+        }
+      }
+
+      // rel is updated (impacts which are represented in the network are set to zero)
+      var rel = variableImpacts.CloneAsMatrix();
+      // make sure the diagonal is not considered
+      for (int i = 0; i < rel.GetLength(0); i++) rel[i, i] = double.NegativeInfinity;
+
+      var addedArcs = AddArcs(network, rel, varNames, targets, varImpactThreshold);
+      while (addedArcs.Any()) {
+        var cycles = network.FindShortestCycles().ToList();
+        while (cycles.Any()) {
+          // delete weakest link
+          var weakestArc = cycles.SelectMany(cycle => network.ArcsForCycle(cycle)).OrderBy(a => a.Weight).First();
+          network.RemoveArc(weakestArc);
+
+          cycles = network.FindShortestCycles().ToList();
+        }
+
+        addedArcs = AddArcs(network, rel, varNames, targets, varImpactThreshold);
+      }
+
+      return network;
+    }
+
+    private static List<IArc> AddArcs(VariableInteractionNetwork network, double[,] impacts, string[] varNames, Dictionary<string, double> targets, double threshold = 0.0) {
+      var newArcs = new List<IArc>();
+      for (int row = 0; row < impacts.GetLength(0); row++) {
+        if (!targets.ContainsKey(varNames[row])) continue;
+
+        var rowVector = Enumerable.Range(0, impacts.GetLength(0)).Select(col => impacts[row, col]).ToArray();
+        var max = rowVector.Max();
+        if (max > threshold) {
+          var idxOfMax = Array.IndexOf<double>(rowVector, max);
+          impacts[row, idxOfMax] = double.NegativeInfinity;
+          var srcName = varNames[idxOfMax];
+          var dstName = varNames[row];
+          var srcVertex = network.Vertices.Single(v => v.Label == srcName);
+          var dstVertex = network.Vertices.Single(v => v.Label == dstName);
+          var arc = network.AddArc(srcVertex, dstVertex);
+          arc.Weight = max;
+          newArcs.Add(arc);
+        }
+      }
+
+      return newArcs;
+    }
+
     /// <summary>
     /// Creates a network from a matrix of variable impacts (each row represents a target variable, each column represents an input variable)
@@ -262,4 +336,26 @@
     }
 
+    public DoubleMatrix GetSimpleWeightsMatrix() {
+      var names = Vertices.OfType<VariableNetworkNode>()
+        .Select(v => v.Label)
+        .OrderBy(s => s, new NaturalStringComparer()).ToArray();
+      var w = new double[names.Length, names.Length];
+
+      var name2idx = new Dictionary<string, int>();
+      for (int i = 0; i < names.Length; i++) {
+        name2idx.Add(names[i], i);
+      }
+
+      foreach (var arc in Arcs) {
+        if (arc.Target != null) {
+          var srcVarName = arc.Source.Label;
+          var dstVarName = arc.Target.Label;          
+          w[name2idx[dstVarName], name2idx[srcVarName]] = arc.Weight;
+        }
+      }
+
+      return new DoubleMatrix(w, names, names);
+    }
+
     public string ToGraphVizString() {
       Func<string, string> NodeAndEdgeColor = (str) =>
