/// <summary>

        /// Solves this instance.

        /// </summary>

        /// <returns>IFeatureClass.</returns>

        public IFeatureClass Solve()

        {

            log.WriteLog("Solving...");

            IGPMessages gpMessages = new GPMessagesClass();

            try

            {

                ConfigureSolverSettings();

                m_NAContext.Solver.Solve(m_NAContext, gpMessages, null);

                return m_NAContext.NAClasses.get_ItemByName("SALines") as IFeatureClass;

            }

            catch (Exception e)

            {

                log.WriteLog("GP执行失败:" + e.Message);

                return null;

            }

            finally

            {

                ////记录GPMessages

                string sGPMessages = GetGPMessagesAsString(gpMessages);

                log.WriteLog("GP执行信息:" + sGPMessages);

                log.WriteLog("Solve完成!");

            }

        }

/// <summary>

        /// Prepare the solver

        /// </summary>

        private void ConfigureSolverSettings()

        {

            ConfigureSettingsSpecificToServiceAreaSolver();

            ConfigureGenericSolverSettings();

            UpdateContextAfterChangingSettings();

        }

        /// <summary>

        /// Update settings that only apply to the Service Area

        /// </summary>

        private void ConfigureSettingsSpecificToServiceAreaSolver()

        {

            INAServiceAreaSolver naSASolver = m_NAContext.Solver as INAServiceAreaSolver;

            naSASolver.DefaultBreaks = ParseBreaks("");

            naSASolver.MergeSimilarPolygonRanges = false;

            naSASolver.OutputPolygons = esriNAOutputPolygonType.esriNAOutputPolygonNone;

            naSASolver.OverlapLines = false;

            naSASolver.SplitLinesAtBreaks = true;

            naSASolver.TravelDirection = esriNATravelDirection.esriNATravelDirectionFromFacility;

            naSASolver.OutputLines = esriNAOutputLineType.esriNAOutputLineTrueShape;

        }

        /// <summary>

        /// Update settings that apply to all solvers

        /// </summary>

        private void ConfigureGenericSolverSettings()

        {

            INASolverSettings naSolverSettings = m_NAContext.Solver as INASolverSettings;

            naSolverSettings.ImpedanceAttributeName = "Time";

            // set the oneway restriction, if necessary

            IStringArray restrictions = naSolverSettings.RestrictionAttributeNames;

            restrictions.RemoveAll();

            naSolverSettings.RestrictionAttributeNames = restrictions;

            //naSolverSettings.RestrictUTurns = esriNetworkForwardStarBacktrack.esriNFSBNoBacktrack;

        }

        /// <summary>

        /// When the solver has been update, the context must be updated as well

        /// </summary>

        private void UpdateContextAfterChangingSettings()

        {

            IDatasetComponent datasetComponent = m_NAContext.NetworkDataset as IDatasetComponent;

            IDENetworkDataset deNetworkDataset = datasetComponent.DataElement as IDENetworkDataset;

            m_NAContext.Solver.UpdateContext(m_NAContext, deNetworkDataset, new GPMessagesClass());

        }

/// <summary>

        /// Prepare the text string for breaks

        /// </summary>

        /// <param name="p">The p.</param>

        /// <returns>IDoubleArray.</returns>

        private IDoubleArray ParseBreaks(string p)

        {

            String[] breaks = p.Split(' ');

            IDoubleArray pBrks = new DoubleArrayClass();

            int firstIndex = breaks.GetLowerBound();

            int lastIndex = breaks.GetUpperBound();

            for (int splitIndex = firstIndex; splitIndex <= lastIndex; splitIndex++)

            {

                try

                {

                    pBrks.Add(Convert.ToDouble(breaks[splitIndex]));

                }

                catch (FormatException)

                {

                    log.WriteLog("Breaks are not properly formatted.  Use only digits separated by spaces");

                    pBrks.RemoveAll();

                    return pBrks;

                }

            }

            return pBrks;

        }

/// <summary>

        /// Gets the GP messages as string.

        /// </summary>

        /// <param name="gpMessages">The gp messages.</param>

        /// <returns>System.String.</returns>

        public string GetGPMessagesAsString(IGPMessages gpMessages)

        {

            // Gather Error/Warning/Informative Messages

            var messages = new StringBuilder();

            if (gpMessages != null)

            {

                for (int i = ; i < gpMessages.Count; i++)

                {

                    IGPMessage gpMessage = gpMessages.GetMessage(i);

                    string message = gpMessage.Description;

                    switch (gpMessages.GetMessage(i).Type)

                    {

                        case esriGPMessageType.esriGPMessageTypeError:

                            messages.AppendLine("Error " + gpMessage.ErrorCode + ": " + message);

                            break;

                        case esriGPMessageType.esriGPMessageTypeWarning:

                            messages.AppendLine("Warning: " + message);

                            break;

                        default:

                            messages.AppendLine("Information: " + message);

                            break;

                    }

                }

            }

            return messages.ToString();

        }

Solve的更多相关文章

  1. Solve VS2010 Error "Exceptions has been thrown by the target of an invocation"

    Sometimes when you open a VS2010 project, an error window will pop up with the error message "E ...

  2. solve the problem of 'java web project cannot display verification code'

    my java code of the function: package com.util; import java.awt.Color; import java.awt.Font; import ...

  3. HDU1086You can Solve a Geometry Problem too(判断线段相交)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  4. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  5. ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

    Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  6. hdu 1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  7. 数论 - 组合数学 + 素数分解 --- hdu 2284 : Solve the puzzle, Save the world!

    Solve the puzzle, Save the world! Problem Description In the popular TV series Heroes, there is a ta ...

  8. hdu 2199 Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. 看ImplicitBackwardEulerSparse关于static solve的代码

    当选择static solve的时候,求解的流程如下: 1.获得内力 2.qresidual = 外力-内力,qdelta = qresidual, qdelta的非约束元素赋给bufferConst ...

随机推荐

  1. apache+mysql+php的环境配置

    一 配置前的准备 1 先设置环境变量(win7的) win10 二 配置apache 我用EditPlus打开httpd.conf LoadModule php5_module  "c:/w ...

  2. NHibernate Profiler使用方法

    NHibernate Profiler是一款可以监视NHibernate里的sql语句的工具 1.下载NHibernate Profiler 2.在你的NHibernate项目中添加引用(在NHibe ...

  3. sqlserver如何创建镜像图文教程(转)

    由于工作中需要做SQL的镜像异地备份,以前都没有研究过,百度了一个文章记录下,方便以后查询 转载地址:http://jingyan.baidu.com/article/d5c4b52b20843fda ...

  4. [转]【无私分享:ASP.NET CORE 项目实战(第九章)】创建区域Areas,添加TagHelper

    本文转自:http://www.cnblogs.com/zhangxiaolei521/p/5808417.html 目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 在Asp ...

  5. HashMap实现原理及源码分析

    哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表,而HashMap的实现原理也常常出 ...

  6. OpenStack 企业私有云的若干需求(1):Nova 虚机支持 GPU

    本系列会介绍OpenStack 企业私有云的几个需求: 自动扩展(Auto-scaling)支持 多租户和租户隔离 (multi-tenancy and tenancy isolation) 混合云( ...

  7. POJ3422 Kaka's Matrix Travels[费用流]

    Kaka's Matrix Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9522   Accepted:  ...

  8. Unity3D脚本行尾(Line Endings)

    行尾不一致(inconsistent line endings ) 开发环境 有时候编辑Unity的脚本文件,代码diff之后,或者从svn更新文件之后,Unity中会出现行尾不一致的信息. 我的开发 ...

  9. BZOJ 1797: [Ahoi2009]Mincut 最小割

    1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2076  Solved: 885[Submit] ...

  10. Dump中查看DataTime时间方法

    例如: 步骤一:根据DumpVC命令获取时间对象信息.需要MT 和 Value参数. 步骤二:根据得到上上面值,执行:? & 0x3FFFFFFFFFFFFFFF.注意:0n 签名是零,不是英 ...