/*------------------------------------------------------------------------- * 功能描述:BinaryRelationItem * 作者:xulisong * 创建时间: 2019/1/22 16:38:20 * 版本号:v1.0 * -------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SAGA.GplotRelationComputerManage { /// /// 二元关系类 /// public class BinaryRelationItem { /// /// 开始节点 /// public EquipmentNode From { get; set; } /// /// 结束节点 /// public EquipmentNode To { get; set; } /// /// 关联类型 /// public string RelationType { get; set; } /// /// 反转关系 /// public void Reverse() { var temp = To; To = From; From = temp; } /// /// 是否是设备连接 /// /// public bool IsEquipmentLink() { return From.IsRealEquipment && To.IsRealEquipment; } /// /// 获取指定条件的Node /// /// /// /// -1表示没有,0,From;1,To public int TryGetNode(Predicate match, out EquipmentNode node) { node = null; var list = new List() {From, To}; for (int i = 0; i < list.Count; i++) { if (match(From)) { node = From; return i; } } return -1; } /// /// 获取匹配元素之外的另一个节点 /// /// /// public EquipmentNode GetAnotherNode(Predicate match) { //只有有一个相等,才称得上另一个 var list = new List() { From, To }; for (int i = 0; i < list.Count; i++) { if (match(From)) { return list[i%2]; } } return null; } } }