コード例 #1
0
ファイル: VEF.cs プロジェクト: roice3/Honeycombs
        /// <summary>
        /// Load from a VEF file.
        /// </summary>
        /// <param name="fileName"></param>
        public void Load( string fileName )
        {
            IEnumerator<string> lines = File.ReadLines( fileName ).GetEnumerator();

            lines.MoveNext();
            int numVertices = int.Parse( lines.Current );

            List<GoldenVector4D> vertices = new List<GoldenVector4D>();
            for( int i = 0; i < numVertices; i++ )
            {
                lines.MoveNext();
                GoldenVector4D v = new GoldenVector4D();
                v.ReadVector( lines.Current );
                vertices.Add( v );
            }

            lines.MoveNext();
            int numEdges = int.Parse( lines.Current );
            List<Edge> edges = new List<Edge>();
            for( int i = 0; i < numEdges; i++ )
            {
                lines.MoveNext();
                Edge e = new Edge();
                e.ReadEdge( lines.Current );
                edges.Add( e );
            }

            this.Vertices = vertices.ToArray();
            this.Edges = edges.ToArray();
        }
コード例 #2
0
ファイル: GraphRelaxation.cs プロジェクト: roice3/Honeycombs
        public void AddEdge( Edge e )
        {
            List<int> vals;

            if( m_connections.TryGetValue( e.V1, out vals ) )
                vals.Add( e.V2 );
            else
                m_connections[e.V1] = new List<int>( new int[] { e.V2 } );

            if( m_connections.TryGetValue( e.V2, out vals ) )
                vals.Add( e.V1 );
            else
                m_connections[e.V2] = new List<int>( new int[] { e.V1 } );

            Edges.Add( e );
        }
コード例 #3
0
ファイル: Sandbox.cs プロジェクト: roice3/Honeycombs
        // http://math.stackexchange.com/questions/142112/how-to-construct-a-k-regular-graph
        // k-regular graph on n vertices.
        public static void Graph()
        {
            HashSet<Edge> edges = new HashSet<Edge>();

            int k = 24, n = 350;
            //int k = 7, n = 24;

            if( k%2 == 0 )
            {
                int increment = n / ( k + 1 );
                increment = 1;

                for( int i=0; i<n; i++ )
                for( int j=1; j<=k/2; j++ )
                {
                    int t1 = Clamp( i + j*increment, n );
                    int t2 = Clamp( i - j*increment, n );

                    Edge e1 = new Edge( i, t1 );
                    Edge e2 = new Edge( i, t2 );
                    edges.Add( e1 );
                    edges.Add( e2 );
                }
            }
            else
            {
                int m = k / 2;
                for( int i=0; i<n; i++ )
                {
                    for( int j=1; j<=m; j++ )
                    {
                        int t1 = Clamp( i + j, n );
                        int t2 = Clamp( i - j, n );

                        Edge e1 = new Edge( i, t1 );
                        Edge e2 = new Edge( i, t2 );
                        edges.Add( e1 );
                        edges.Add( e2 );
                    }

                    int t3 = Clamp( i + n/2, n );
                    edges.Add( new Edge( i, t3 ) );
                }
            }

            using( StreamWriter sw = File.CreateText( "733.csv" ) )
            {
                foreach( Edge e in edges )
                {
                    sw.WriteLine( string.Format( "master{0};master{1}", e.V1, e.V2 ) );
                }
            }
        }