/// <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. IE8 ajax缓存问题

    娘希匹,又遇到缓存问题了. 下面的代码,在其他浏览器都是正常的,但是在IE8中出现诡异问题. $.ajax({ url:dataUrl, data:encodeURI(currentjsonform) ...

  2. MySQL调优系列_日志分析

    前言 本篇主要总结一下MySQL数据库的几种日志,用于日常维护过程中问题解决和性能优化等,稍显基础,日常积累之用. 文章的部分内容会将MySQL数据库和SQL Server数据库部分内容做一个对比,非 ...

  3. 深入解析SQL Server并行执行原理及实践(下)

    谈完并行执行的原理,咱们再来谈谈优化,到底并行执行能给我们带来哪些好处,我们又应该注意什么呢,下面展开. Amdahl’s  Law 再谈并行优化前我想有必要谈谈阿姆达尔定律,可惜老爷子去年已经驾鹤先 ...

  4. Java通过几种经典的算法来实现数组排序

    Java实现数组排序 package com.souvc.hibernate.exp; public class MySort { /** * 方法名:main</br> * 详述:Jav ...

  5. Python写地铁的到站的原理简易版

    Python地铁的到站流程及原理(个人理解) 今天坐地铁看着站牌就莫名的想如果用Python写其工作原理 是不是很简单就小试牛刀了下大佬们勿喷纯属小弟个人理解 首先来看看地铁上显示的站牌如下: 就想这 ...

  6. sublime text3的一些插件安装方法和使用

    sublime text部分插件使用方法在线安装package Control的方法:    ctrl+~ 输入如下代码:        import urllib2,os; pf='Package ...

  7. Windows 10 安装双系统 CentOS 7

    系统环境:Windows 10 && CentOS 7 准备工具: ●CentOS7 官网下载地址:https://wiki.centos.org/Download (注意: i386 ...

  8. register_shutdown_function AND fastcgi_finish_request

    在php中又两个方法都是在请求快结束的时候执行.方法名分别是 register_shutdown_function和fastcgi_finish_request.虽然执行的时机差不多,但是功能和应用场 ...

  9. Leetcode: word search

    July 6, 2015 Problem statement: Word Search Given a 2D board and a word, find if the word exists in ...

  10. sql 入门经典(第五版) Ryan Stephens 学习笔记 后续——存储引擎

    一.引擎基础 1 查看系统支持的存储引擎 show engines; 2 查看表使用的存储引擎两种方法: a.show table status from database_name where na ...