/// <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. linux shell for循环使用命令中读取到的值实例

    #!/bin/bash file="states" for state in `cat $file` do echo "Visit beautiful $state&qu ...

  2. 交互式makefile

    之前一直不知道在shell中调用read赋值后,怎么传给makefile中的变量,后来才恍然大悟. myname := $(shell read -p "Enter your name:&q ...

  3. 常用python机器学习库总结

    开始学习Python,之后渐渐成为我学习工作中的第一辅助脚本语言,虽然开发语言是Java,但平时的很多文本数据处理任务都交给了Python.这些年来,接触和使用了很多Python工具包,特别是在文本处 ...

  4. 虚基类&虚继承

    发现这个月准备竞赛完全没有更新哎... 改了下某华大一c++测试题...网上对虚继承讲的要么太繁琐要么不到位,自力更生 #include<iostream> #include<fst ...

  5. 【2016-10-27】【坚持学习】【Day14】【GlobalAssemblyInfo 】

    当一个解决方案,有多个项目时候,每一个项目的AssemblyInfo 都要写相同的东西.麻烦,因此使用GlobalAssemblyInfo 来统一管理. 实现如下: 在解决方案下增加一个文件夹以及Gl ...

  6. [No000088]并行循环vs普通循环

    using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks ...

  7. 操作系统IO模型

    操作系统IO模型 声明:如下内容是根据APUE和mycat两本著作中关于I/O模式的一些内容加上自己的一些理解整理而成,仅供学习使用. 本节内容 UNIX下可用的五种I/O模型 三种I/O模型 Rea ...

  8. HTML5中支持新的媒体元素有这些

    HTML5对媒体的支持性很强,支持以下媒体元素: · audio  定义音频 · video  定义视频 · embed  作为外部应用的容器 · source  多种媒体源的支持 · track   ...

  9. BZOJ2748[HAOI2012]音量调节

    Description 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量.在演出开始之前,他已经做好了一个列表,里面写着在每首歌开始之前他想要改 ...

  10. 在线文档预览方案-office web apps续篇

    上一篇在线文档预览方案-office web apps发布后收到很多网友的留言提问,所以准备再写一篇,一来介绍一下域控服务器安装,总结一下大家问的多的问题,二来宣传预览服务安装与技术支持的事情. 阅读 ...