public static DataSet Search(string[] searchs, PageContent objPage) { ScopeList lstScope = new ScopeList(); lstScope.PageContent = objPage; double per = Math.Pow(2, searchs.Length); lstScope.ShowProperty.Add(Management.SampleInfo.SampleName.As("SampleName")); lstScope.ShowProperty.Add(Management.SampleInfo.SamplingTerrace.As("SamplingTerrace")); lstScope.ShowProperty.Add(Management.SampleInfo.SampleNumber.As("SampleNumber")); BQLValueItem perValue = BQLValueItem.ToValueItem(0); BQLCondition nameCon = BQLCondition.FalseValue; foreach (string search in searchs) { nameCon = nameCon | Management.SampleInfo.SampleName.Like(search); perValue = perValue + BQL.Case().When(BQL.ToParam("SampleName").IndexOf(search, 0) <= 0).Then(0).Else(1).End *per; per /= 2; } lstScope.ShowProperty.Add(perValue.As("per1")); lstScope.Add(nameCon); lstScope.OrderBy.Add(perValue.As("").DESC); per = Math.Pow(2, searchs.Length); perValue = BQLValueItem.ToValueItem(0); nameCon = BQLCondition.FalseValue; foreach (string search in searchs) { nameCon = nameCon | Management.SampleInfo.SamplingTerrace.Like(search); perValue = perValue + BQL.Case().When(BQL.ToParam("SamplingTerrace").IndexOf(search, 0) <= 0).Then(0).Else(1).End *per; per /= 2; } lstScope.ShowProperty.Add(perValue.As("per2")); lstScope.Add(nameCon, ConnectType.OR); lstScope.OrderBy.Add(perValue.As("").DESC); per = Math.Pow(2, searchs.Length); perValue = BQLValueItem.ToValueItem(0); nameCon = BQLCondition.FalseValue; foreach (string search in searchs) { nameCon = nameCon | Management.SampleInfo.SampleNumber.Like(search); perValue = perValue + BQL.Case().When(BQL.ToParam("SampleNumber").IndexOf(search, 0) <= 0).Then(0).Else(1).End *per; per /= 2; } lstScope.ShowProperty.Add(perValue.As("per3")); lstScope.Add(nameCon, ConnectType.OR); lstScope.OrderBy.Add(perValue.As("").DESC); //lstScope.OrderBy.Add(BQL.ToParam("per1").DESC); //lstScope.OrderBy.Add(BQL.ToParam("per2").DESC); //lstScope.OrderBy.Add(BQL.ToParam("per3").DESC); return(GetContext().Select(lstScope)); }
/// <summary> /// 获取唯一 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition">条件</param> /// <returns></returns> public static T GetUnique <T>(BQLCondition condition) where T : EntityBase, new() { ScopeList lstScope = new ScopeList(); if (!CommonMethods.IsNull(condition)) { lstScope.Add(condition); } return(GetUnique <T>(lstScope)); }
/// <summary> /// 查询数目 /// </summary> /// <param name="condition">条件</param> /// <returns></returns> public static long SelectCount <T>(BQLCondition condition) where T : EntityBase, new() { ScopeList lstScope = new ScopeList(); if (!CommonMethods.IsNull(condition)) { lstScope.Add(condition); } return(SelectCount <T>(lstScope)); }
/// <summary> /// 查询集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition">条件</param> /// <param name="pager">分页条件</param> /// <returns></returns> public static List <T> SelectList <T>(BQLCondition condition, PageContent pager) where T : EntityBase, new() { ScopeList lstScope = new ScopeList(); if (!CommonMethods.IsNull(condition)) { lstScope.Add(condition); } if (pager != null) { lstScope.PageContent = pager; } return(SelectList <T>(lstScope)); }
/// <summary> /// 获取唯一 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition">条件</param> /// <returns></returns> public static T GetUnique <T>(BQLCondition condition) where T : EntityBase, new() { string name = typeof(T).FullName; BusinessModelBase <T> bo = DataAccessLoader.GetBoInstance(name) as BusinessModelBase <T>; if (bo == null) { throw new MissingMemberException("找不到:" + name + " 对应的业务类"); } ScopeList lstScope = new ScopeList(); if (!CommonMethods.IsNull(condition)) { lstScope.Add(condition); } return(bo.GetUnique(lstScope)); }
public override IOperation Apply() { bool dominateOnEqualQualities = DominateOnEqualQualitiesParameter.ActualValue.Value; bool[] maximization = MaximizationParameter.ActualValue.ToArray(); double[][] qualities = QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(); if (qualities == null) { throw new InvalidOperationException(Name + ": No qualities found."); } IScope scope = ExecutionContext.Scope; int populationSize = scope.SubScopes.Count; List <ScopeList> fronts = new List <ScopeList>(); Dictionary <IScope, List <int> > dominatedScopes = new Dictionary <IScope, List <int> >(); int[] dominationCounter = new int[populationSize]; ItemArray <IntValue> rank = new ItemArray <IntValue>(populationSize); for (int pI = 0; pI < populationSize - 1; pI++) { IScope p = scope.SubScopes[pI]; List <int> dominatedScopesByp; if (!dominatedScopes.TryGetValue(p, out dominatedScopesByp)) { dominatedScopes[p] = dominatedScopesByp = new List <int>(); } for (int qI = pI + 1; qI < populationSize; qI++) { DominationResult test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities); if (test == DominationResult.Dominates) { dominatedScopesByp.Add(qI); dominationCounter[qI] += 1; } else if (test == DominationResult.IsDominated) { dominationCounter[pI] += 1; if (!dominatedScopes.ContainsKey(scope.SubScopes[qI])) { dominatedScopes.Add(scope.SubScopes[qI], new List <int>()); } dominatedScopes[scope.SubScopes[qI]].Add(pI); } if (pI == populationSize - 2 && qI == populationSize - 1 && dominationCounter[qI] == 0) { rank[qI] = new IntValue(0); AddToFront(scope.SubScopes[qI], fronts, 0); } } if (dominationCounter[pI] == 0) { rank[pI] = new IntValue(0); AddToFront(p, fronts, 0); } } int i = 0; while (i < fronts.Count && fronts[i].Count > 0) { ScopeList nextFront = new ScopeList(); foreach (IScope p in fronts[i]) { List <int> dominatedScopesByp; if (dominatedScopes.TryGetValue(p, out dominatedScopesByp)) { for (int k = 0; k < dominatedScopesByp.Count; k++) { int dominatedScope = dominatedScopesByp[k]; dominationCounter[dominatedScope] -= 1; if (dominationCounter[dominatedScope] == 0) { rank[dominatedScope] = new IntValue(i + 1); nextFront.Add(scope.SubScopes[dominatedScope]); } } } } i += 1; fronts.Add(nextFront); } RankParameter.ActualValue = rank; scope.SubScopes.Clear(); for (i = 0; i < fronts.Count; i++) { Scope frontScope = new Scope("Front " + i); foreach (var p in fronts[i]) { frontScope.SubScopes.Add(p); } if (frontScope.SubScopes.Count > 0) { scope.SubScopes.Add(frontScope); } } return(base.Apply()); }
public override IOperation Apply() { bool dominateOnEqualQualities = DominateOnEqualQualitiesParameter.ActualValue.Value; bool[] maximization = MaximizationParameter.ActualValue.ToArray(); double[][] qualities = QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(); if (qualities == null) throw new InvalidOperationException(Name + ": No qualities found."); IScope scope = ExecutionContext.Scope; int populationSize = scope.SubScopes.Count; List<ScopeList> fronts = new List<ScopeList>(); Dictionary<IScope, List<int>> dominatedScopes = new Dictionary<IScope, List<int>>(); int[] dominationCounter = new int[populationSize]; ItemArray<IntValue> rank = new ItemArray<IntValue>(populationSize); for (int pI = 0; pI < populationSize - 1; pI++) { IScope p = scope.SubScopes[pI]; List<int> dominatedScopesByp; if (!dominatedScopes.TryGetValue(p, out dominatedScopesByp)) dominatedScopes[p] = dominatedScopesByp = new List<int>(); for (int qI = pI + 1; qI < populationSize; qI++) { DominationResult test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities); if (test == DominationResult.Dominates) { dominatedScopesByp.Add(qI); dominationCounter[qI] += 1; } else if (test == DominationResult.IsDominated) { dominationCounter[pI] += 1; if (!dominatedScopes.ContainsKey(scope.SubScopes[qI])) dominatedScopes.Add(scope.SubScopes[qI], new List<int>()); dominatedScopes[scope.SubScopes[qI]].Add(pI); } if (pI == populationSize - 2 && qI == populationSize - 1 && dominationCounter[qI] == 0) { rank[qI] = new IntValue(0); AddToFront(scope.SubScopes[qI], fronts, 0); } } if (dominationCounter[pI] == 0) { rank[pI] = new IntValue(0); AddToFront(p, fronts, 0); } } int i = 0; while (i < fronts.Count && fronts[i].Count > 0) { ScopeList nextFront = new ScopeList(); foreach (IScope p in fronts[i]) { List<int> dominatedScopesByp; if (dominatedScopes.TryGetValue(p, out dominatedScopesByp)) { for (int k = 0; k < dominatedScopesByp.Count; k++) { int dominatedScope = dominatedScopesByp[k]; dominationCounter[dominatedScope] -= 1; if (dominationCounter[dominatedScope] == 0) { rank[dominatedScope] = new IntValue(i + 1); nextFront.Add(scope.SubScopes[dominatedScope]); } } } } i += 1; fronts.Add(nextFront); } RankParameter.ActualValue = rank; scope.SubScopes.Clear(); for (i = 0; i < fronts.Count; i++) { Scope frontScope = new Scope("Front " + i); foreach (var p in fronts[i]) frontScope.SubScopes.Add(p); if (frontScope.SubScopes.Count > 0) scope.SubScopes.Add(frontScope); } return base.Apply(); }