コード例 #1
0
ファイル: GraphService.cs プロジェクト: politician/fallen-8
 public List<PathREST> GetPathsByVertex(string from, string to, PathSpecification definition)
 {
     return GetPaths(from, to, definition);
 }
コード例 #2
0
ファイル: GraphService.cs プロジェクト: politician/fallen-8
        /// <summary>
        /// Create the source for the code generation
        /// </summary>
        /// <param name="definition">The path specification</param>
        /// <returns>The source code</returns>
        private string CreateSource(PathSpecification definition)
        {
            if (definition == null) return string.Empty;

            var sb = new StringBuilder();
            sb.AppendLine(_pathDelegateClassPrefix);

            if (definition.Cost != null)
            {
                if (definition.Cost.Edge != null)
                {
                    sb.AppendLine(definition.Cost.Edge);
                }

                if (definition.Cost.Vertex != null)
                {
                    sb.AppendLine(definition.Cost.Vertex);
                }
            }

            if (definition.Filter != null)
            {
                if (definition.Filter.Edge != null)
                {
                    sb.AppendLine(definition.Filter.Edge);
                }

                if (definition.Filter.EdgeProperty != null)
                {
                    sb.AppendLine(definition.Filter.EdgeProperty);
                }

                if (definition.Filter.Vertex != null)
                {
                    sb.AppendLine(definition.Filter.Vertex);
                }
            }

            sb.AppendLine(_pathDelegateClassSuffix);

            return sb.ToString();
        }
コード例 #3
0
ファイル: GraphService.cs プロジェクト: politician/fallen-8
        public List<PathREST> GetPaths(string from, string to, PathSpecification definition)
        {
            if (definition != null)
            {
                var fromId = Convert.ToInt32(from);
                var toId = Convert.ToInt32(to);

                var results = _codeProvider.CompileAssemblyFromSource(_compilerParameters, new[] { CreateSource(definition) });

                if (results.Errors.HasErrors)
                {
                    throw new Exception(CreateErrorMessage(results.Errors));
                }

                var type = results.CompiledAssembly.GetType(PathDelegateClassName);

                var edgeCostDelegate = CreateEdgeCostDelegate(definition.Cost, type);
                var vertexCostDelegate = CreateVertexCostDelegate(definition.Cost, type);

                var edgePropertyFilterDelegate = CreateEdgePropertyFilterDelegate(definition.Filter, type);
                var vertexFilterDelegate = CreateVertexFilterDelegate(definition.Filter, type);
                var edgeFilterDelegate = CreateEdgeFilterDelegate(definition.Filter, type);

                List<Path> paths;
                if (_fallen8.CalculateShortestPath(
                    out paths,
                    definition.PathAlgorithmName,
                    fromId,
                    toId,
                    definition.MaxDepth,
                    definition.MaxPathWeight,
                    definition.MaxResults,
                    edgePropertyFilterDelegate,
                    vertexFilterDelegate,
                    edgeFilterDelegate,
                    edgeCostDelegate,
                    vertexCostDelegate))
                {
                    if (paths != null)
                    {
                        return new List<PathREST>(paths.Select(aPath => new PathREST(aPath)));
                    }
                }
            }
            return null;
        }