private static void _SaveRouteAttributes(XmlWriter writer, Route route, IVrpSolver solver) { bool attributesContainsParams = false; Debug.Assert(solver.NetworkDescription != null); foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes) { foreach (NetworkAttributeParameter parameter in attribute.Parameters) { attributesContainsParams = true; break; } if (attributesContainsParams) { break; } } if (attributesContainsParams) { SolverSettings solverSettings = solver.SolverSettings; writer.WriteStartElement(ATTRIBUTE_PARAMS_NODE_NAME); foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes) { bool containsParams = false; foreach (NetworkAttributeParameter parameter in attribute.Parameters) { containsParams = true; break; } if (containsParams) { writer.WriteStartElement(ATTRIBUTE_NODE_NAME); writer.WriteAttributeString(NAME_ATTR_NAME, attribute.Name); foreach (NetworkAttributeParameter parameter in attribute.Parameters) { writer.WriteStartElement(PARAM_NODE_NAME); writer.WriteAttributeString(NAME_ATTR_NAME, parameter.Name); object valueObj = null; if (!solverSettings.GetNetworkAttributeParameterValue(attribute.Name, parameter.Name, out valueObj)) { valueObj = null; } string value = _ConvertValue2String(valueObj); writer.WriteAttributeString(VALUE_ATTR_NAME, value); writer.WriteEndElement(); } writer.WriteEndElement(); } } writer.WriteEndElement(); } }
/// <summary> /// Get value for parameter. /// </summary> /// <param name="attributeName">Attribute name.</param> /// <param name="parameterName">Parameter name.</param> /// <param name="solverSettings">Solver settings from which /// parameter value will be taken.</param> /// <returns>Parameter value or empty string if no such parameter.</returns> private string _GetParameterValue(string attributeName, string parameterName, SolverSettings solverSettings) { object valueObj = null; if (!solverSettings.GetNetworkAttributeParameterValue(attributeName, parameterName, out valueObj)) { valueObj = null; } return(_ConvertValue2String(valueObj)); }
/// <summary> /// Update parameter if it has been changed. /// </summary> /// <param name="solverSettings">Solver settings in which /// parameter value will be updated.</param> /// <param name="attribute">Network attribute, which parameter must be updated.</param> /// <param name="parameterName">Name of the parameter which must be updated.</param> /// <param name="parameterValue">Value, which must be set in parameter.</param> /// <exception cref="System.ArgumentException">Is thrown when there is no /// attribute with such parameter name in solver settings.</exception> private void _UpdateParameterIfNeeded(SolverSettings solverSettings, NetworkAttribute attribute, string parameterName, string parameterValue) { Debug.Assert(solverSettings != null); Debug.Assert(attribute != null); Debug.Assert(parameterName != null); // Get parameter. var parameter = attribute.Parameters.First(par => par.Name == parameterName); // Get current parameter value. object valueObj = null; if (!solverSettings.GetNetworkAttributeParameterValue(attribute.Name, parameterName, out valueObj)) { throw new ArgumentException("parameterName"); } string value = _ConvertValue2String(valueObj); // If value has changed - set new value. if (!value.Equals(parameterValue, StringComparison.OrdinalIgnoreCase)) { if (parameterValue != null) { try { solverSettings.SetNetworkAttributeParameterValue(attribute.Name, parameter.Name, parameterValue); } // Inputed value is in wrong format - do not change solver settings. catch { } } } }