Esempio n. 1
0
        /// <summary>
        /// Adds edgeCount number of edges to network.  AllowMultiEdges and AllowSelfLoops will affect
        /// how edges are added.
        /// </summary>
        public static void CreateEdges(INetworkAdjList network, int edgeCount)
        {
            Random rand = new Random(DateTime.Now.Millisecond);

            int srcNodeIndex = -1;
            int destNodeIndex = -1;
            INode srcNode = null;
            INode destNode = null;

            for (int i = 0; i < edgeCount; i++)
            {
                srcNodeIndex = rand.Next(network.NodeCount);
                destNodeIndex = rand.Next(network.NodeCount);
                srcNode = network.Nodes[srcNodeIndex];
                destNode = network.Nodes[destNodeIndex];

                if (!AllowMultiEdges && AllowSelfLoops)
                {
                    if (network.IsEdge(srcNode, destNode))
                        continue;
                    else
                        network.CreateEdge(srcNode, destNode);
                }
                else if (AllowMultiEdges && !AllowSelfLoops)
                {
                    if (srcNode == destNode)
                        continue;
                    else
                        network.CreateEdge(srcNode, destNode);
                }
                else
                    network.CreateEdge(srcNode, destNode);
            }
        }
Esempio n. 2
0
 internal void CopyColumnToMap(DataTable table, int srcColIndex, INetworkAdjList network, IEdgeIntMap map)
 {
     int ctr = 0;
     foreach (IEdge edge in network.EdgeEnumerator)
     {
         map[edge] = (int)table.Rows[ctr++][srcColIndex];
     }
 }
Esempio n. 3
0
 internal void ConvertColumnToMap(DataTable table, int srcColIndex, INetworkAdjList network, INodeIntMap map)
 {
     int ctr = 0;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = System.Convert.ToInt32(table.Rows[ctr++][srcColIndex]);
     }
 }
 public void CopyColumnToMap(DataTable table, int srcColIndex, INetworkAdjList network, INodeStringMap map)
 {
     int ctr = 0;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = (string)table.Rows[ctr++][srcColIndex];
     }
 }
 public void CopyColumnToMap(DataTable table, int srcColIndex, INetworkAdjList network, INodeIntMap map, IList<int> rowIndices)
 {
     int ctr = 0;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = (int)table.Rows[rowIndices[ctr++]][srcColIndex];
     }
 }
Esempio n. 6
0
 internal void ConvertColumnToMap(DataTable table, int srcColIndex, INetworkAdjList network, IEdgeDoubleMap map)
 {
     int ctr = 0;
     foreach (IEdge edge in network.EdgeEnumerator)
     {
         map[edge] = System.Convert.ToDouble(table.Rows[ctr++][srcColIndex]);
     }
 }
Esempio n. 7
0
 public INodeBoolMap SetBoolValues(INetworkAdjList network, int index, object defaultVal)
 {
     INodeBoolMap map = network.CreateNodeMap(LayerDataType._bool, string.Format("bool_{0}", index), defaultVal) as INodeBoolMap;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = Convert.ToBoolean(_Rand.Next(2));
     }
     return map;
 }
Esempio n. 8
0
 public INodeDoubleMap SetDoubleValues(INetworkAdjList network, int index)
 {
     INodeDoubleMap map = network.CreateNodeMap(LayerDataType._double, string.Format("dubs_{0}", index), 0.0) as INodeDoubleMap;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = _Rand.NextDouble();
     }
     return map;
 }
Esempio n. 9
0
 public IEdgeBoolMap SetBoolValues(INetworkAdjList network, int index)
 {
     IEdgeBoolMap map = network.CreateEdgeMap(LayerDataType._bool, string.Format("bool_{0}", index), false) as IEdgeBoolMap;
     foreach (IEdge edge in network.EdgeEnumerator)
     {
         map[edge] = Convert.ToBoolean(_Rand.Next(2));
     }
     return map;
 }
Esempio n. 10
0
        public INodeMap[] AddNodeData(INetworkAdjList network, LayerDataType[] dataTypes)
        {
            INodeMap[] maps = new INodeMap[dataTypes.Length];

            for (int i = 0; i < dataTypes.Length; i++)
            {
                maps[i] = SetValues(dataTypes[i], network, i);
            }
            return maps;
        }
Esempio n. 11
0
 public INodeBoolMap SetBoolValues(INetworkAdjList network, int index, bool[] vals)
 {
     INodeBoolMap map = network.CreateNodeMap(LayerDataType._bool, string.Format("bool_{0}", index), false) as INodeBoolMap;
     int ctr = 0;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = vals[ctr++];
     }
     return map;
 }
Esempio n. 12
0
        public void CopyMapToFrame(INetworkAdjList network, INodeDoubleMap map, IFrame frame)
        {
            double[] vals = new double[network.NodeCount];
            int ctr = 0;
            foreach (INode node in network.NodeEnumerator)
            {
                vals[ctr++] = map[node];
            }

            SimpleFrame sFrame = frame as SimpleFrame;
            using (SimpleFrameTool tool = new SimpleFrameTool())
            {
                tool.AddColumn<double>(sFrame, map.Name, vals);
            }
        }
Esempio n. 13
0
        public void CopyMapToFrame(INetworkAdjList network, IEdgeBoolMap map, IFrame frame)
        {
            bool[] vals = new bool[network.EdgeCount];
            int ctr = 0;
            foreach (IEdge edge in network.EdgeEnumerator)
            {
                vals[ctr++] = map[edge];
            }

            SimpleFrame sFrame = frame as SimpleFrame;
            using (SimpleFrameTool tool = new SimpleFrameTool())
            {
                tool.AddColumn<bool>(sFrame, map.Name, vals);
            }
        }
Esempio n. 14
0
 public INodeMap AddNodeData(INetworkAdjList network, LayerDataType dataType, object defaultVal)
 {
     INodeMap map = null;
     switch (dataType)
     {
         case BlueSpider.Blob.Common.LayerDataType._integer:
             map = SetIntValues(network, 0, defaultVal);
             break;
         case BlueSpider.Blob.Common.LayerDataType._double:
             map = SetDoubleValues(network, 0, defaultVal);
             break;
         case BlueSpider.Blob.Common.LayerDataType._bool:
             map = SetBoolValues(network, 0, defaultVal);
             break;
         case BlueSpider.Blob.Common.LayerDataType._string:
             map = SetStringValues(network, 0, defaultVal);
             break;
     }
     return map;
 }
Esempio n. 15
0
 public void CopyToMap(object source, string srcColName, INetworkAdjList network, IEdgeMap map)
 {
     CheckParameters(source);
     int srcColIndex = ((DataTable)source).Columns[srcColName].Ordinal;
     _CopyToMap((DataTable)source, srcColIndex, network, map);
 }
Esempio n. 16
0
 public void CopyToMap(object source, int srcColIndex, INetworkAdjList network, IEdgeMap map)
 {
     CheckParameters(source);
     _CopyToMap((DataTable)source, srcColIndex, network, map);
 }
Esempio n. 17
0
 private void DoError(object source, int srcColIndex, INetworkAdjList network, IEdgeMap map)
 {
     DataTable table = source as DataTable;
     if (table != null)
     {
         if (srcColIndex >= 0 && srcColIndex < table.Columns.Count)
         {
             Type type = table.Columns[srcColIndex].DataType;
             throw new InvalidOperationException(string.Format(
                 "The column at index {0} with data type {1} cannot be copied to a edge map as this type is not currently supported as a edge attribute.",
                 srcColIndex, type.Name));
         }
         else
         {
             throw new InvalidOperationException(string.Format(
                 "The index of the column to copy must be in the range [0,n) where n is the number of columns in the table; {0} is not a valid column index.",
                 srcColIndex));
         }
     }
     else
     {
         throw new InvalidOperationException(string.Format("The data source object is expected to be an DataTable."));
     }
 }
Esempio n. 18
0
 internal void _CopyToMap(DataTable source, int srcColIndex, INetworkAdjList network, IEdgeMap map)
 {
     if (map is IEdgeIntMap)
     {
         if (source.Columns[srcColIndex].DataType == typeof(int))
             CopyColumnToMap(source, srcColIndex, network, (IEdgeIntMap)map);
         else
             ConvertColumnToMap(source, srcColIndex, network, (IEdgeIntMap)map);
     }
     else if (map is IEdgeDoubleMap)
     {
         if (source.Columns[srcColIndex].DataType == typeof(double))
             CopyColumnToMap(source, srcColIndex, network, (IEdgeDoubleMap)map);
         else
             ConvertColumnToMap(source, srcColIndex, network, (IEdgeDoubleMap)map);
     }
     else if (map is IEdgeBoolMap)
         CopyColumnToMap(source, srcColIndex, network, (IEdgeBoolMap)map);
     else if (map is IEdgeStringMap)
         CopyColumnToMap(source, srcColIndex, network, (IEdgeStringMap)map);
     else
         DoError(source, srcColIndex, network, map);
 }
 public void CopyToMap(object source, string srcColName, INetworkAdjList network, INodeMap map, IList<int> rowIndices)
 {
     int index = ((DataTable)source).Columns[srcColName].Ordinal;
     CopyToMap((DataTable)source, index, network, map, rowIndices);
 }
 public void CopyToMap(DataTable table, int srcColIndex, INetworkAdjList network, INodeMap map)
 {
     if (map is INodeIntMap)
         CopyColumnToMap(table, srcColIndex, network, (INodeIntMap)map);
     else if (map is INodeDoubleMap)
         CopyColumnToMap(table, srcColIndex, network, (INodeDoubleMap)map);
     else if (map is INodeBoolMap)
         CopyColumnToMap(table, srcColIndex, network, (INodeBoolMap)map);
     else if (map is INodeStringMap)
         CopyColumnToMap(table, srcColIndex, network, (INodeStringMap)map);
     else
         DoError(table, srcColIndex, network, map);
 }
 public void CopyToMap(DataTable table, string srcColName, INetworkAdjList network, INodeMap map)
 {
     int index = table.Columns[srcColName].Ordinal;
     CopyToMap(table, index, network, map);
 }
Esempio n. 22
0
 public void CopyToFrame(INetworkAdjList network, IEdgeMap map, IFrame frame)
 {
     if (map is IEdgeIntMap)
         CopyMapToFrame(network, (IEdgeIntMap)map, frame);
     else if (map is IEdgeDoubleMap)
         CopyMapToFrame(network, (IEdgeDoubleMap)map, frame);
     else if (map is IEdgeBoolMap)
         CopyMapToFrame(network, (IEdgeBoolMap)map, frame);
     else if (map is IEdgeStringMap)
         CopyMapToFrame(network, (IEdgeStringMap)map, frame);
     else
     {
         if (map!=null)
         {
             throw new InvalidOperationException(string.Format(
                 "The edge map to copy is of an unsupported type: {0}", LayerDataTypeConverter.ToType(map.DataType).Name));
         }
     }
 }
Esempio n. 23
0
 public INodeMap SetValues(LayerDataType type, INetworkAdjList network, int index)
 {
     INodeMap map = null;
     switch (type)
     {
         case BlueSpider.Blob.Common.LayerDataType._integer:
             map = SetIntValues(network, index);
             break;
         case BlueSpider.Blob.Common.LayerDataType._double:
             map = SetDoubleValues(network, index);
             break;
         case BlueSpider.Blob.Common.LayerDataType._bool:
             map = SetBoolValues(network, index);
             break;
         case BlueSpider.Blob.Common.LayerDataType._string:
             map = SetStringValues(network, index);
             break;
     }
     return map;
 }
Esempio n. 24
0
 public INodeStringMap SetStringValues(INetworkAdjList network, int index, object defaultVal)
 {
     INodeStringMap map = network.CreateNodeMap(LayerDataType._string, string.Format("str_{0}", index), defaultVal) as INodeStringMap;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = string.Format("{0}-XYZ", _Rand.Next(network.NodeCount));
     }
     return map;
 }
 public void CopyToMap(object source, int srcColIndex, INetworkAdjList network, INodeMap map, IList<int> rowIndices)
 {
     if (map is INodeIntMap)
         CopyColumnToMap((DataTable)source, srcColIndex, network, (INodeIntMap)map, rowIndices);
     else if (map is INodeDoubleMap)
         CopyColumnToMap((DataTable)source, srcColIndex, network, (INodeDoubleMap)map, rowIndices);
     else if (map is INodeBoolMap)
         CopyColumnToMap((DataTable)source, srcColIndex, network, (INodeBoolMap)map, rowIndices);
     else if (map is INodeStringMap)
         CopyColumnToMap((DataTable)source, srcColIndex, network, (INodeStringMap)map, rowIndices);
     else
         DoError(source, srcColIndex, network, map);
 }
Esempio n. 26
0
 public void CopyToFrame(INetworkAdjList network, int mapIndex, IFrame frame)
 {
     CopyToFrame(network, network.EdgeMaps[mapIndex], frame);
 }
Esempio n. 27
0
 public INodeDoubleMap SetDoubleValues(INetworkAdjList network, int index, double[] vals)
 {
     INodeDoubleMap map = network.CreateNodeMap(LayerDataType._double, string.Format("dubs_{0}", index), 0.0) as INodeDoubleMap;
     int ctr = 0;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = vals[ctr++];
     }
     return map;
 }
Esempio n. 28
0
 public void CopyToFrame(INetworkAdjList network, string mapName, IFrame frame)
 {
     int index = -1;
     for (int i = 0; i < network.EdgeMapNames.Length; i++)
     {
         if (string.Compare(mapName, network.EdgeMapNames[i])==0)
         {
             index = i;
             break;
         }
     }
     CopyToFrame(network, index, frame);
 }
Esempio n. 29
0
 public INodeIntMap SetIntValues(INetworkAdjList network, int index, object defaultVal)
 {
     INodeIntMap map = network.CreateNodeMap(LayerDataType._integer, string.Format("ints_{0}", index), defaultVal) as INodeIntMap;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = _Rand.Next(network.NodeCount);
     }
     return map;
 }
Esempio n. 30
0
 public INodeIntMap SetIntValues(INetworkAdjList network, int index, int[] vals)
 {
     INodeIntMap map = network.CreateNodeMap(LayerDataType._integer, string.Format("ints_{0}", index), 0) as INodeIntMap;
     int ctr = 0;
     foreach (INode node in network.NodeEnumerator)
     {
         map[node] = vals[ctr++];
     }
     return map;
 }