public override double CalculateFitness(BuildingRule model) { var universities = model.Roads.SelectMany(b => b.Buildings).Count(b => b is University); var schools = model.Roads.SelectMany(b => b.Buildings).Count(b => b is School); if (schools / (universities + 1) < 10) { //("No more than one school per 100 residences"); return(0); } return(15); }
public override double CalculateFitness(BuildingRule model) { var residences = model.Roads.SelectMany(b => b.Buildings).Count(b => b is Residence); var schools = model.Roads.SelectMany(b => b.Buildings).Count(b => b is School); if (residences / (schools + 1) < 500) { //("No more than one school per 500 residences"); return(0); } return(7); }
public async Task <BuildingRule> SaveAsync(SimpleUser user, BuildingRule buildingRule, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (buildingRule == null) { throw new ArgumentNullException(nameof(buildingRule)); } //查看楼盘是否存在 if (!Context.Buildings.Any(x => x.Id == buildingRule.Id)) { Buildings buildings = new Buildings() { Id = buildingRule.Id, CreateUser = user.Id, ResidentUser1 = user.Id, CreateTime = DateTime.Now, OrganizationId = user.OrganizationId, ExamineStatus = 0 }; Context.Add(buildings); } //基本信息 if (!Context.BuildingRules.Any(x => x.Id == buildingRule.Id)) { Context.Add(buildingRule); } else { Context.Attach(buildingRule); Context.Update(buildingRule); } try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { } return(buildingRule); }
public override double CalculateFitness(BuildingRule model) { var minDistanceBetweenChurches = 30; var churches = model.Roads.SelectMany(b => b.Buildings).Where(b => b != this && b is Church); if (!churches.All(m => m.Position.DistanceTo(this.Position) >= minDistanceBetweenChurches)) { return(0); } var residences = model.Roads.SelectMany(b => b.Buildings).Where(b => b is Residence); if (residences.Count(r => r.Position.DistanceTo(this.Position) <= 30) < 500) { return(0); } return(5); }
public override double CalculateFitness(BuildingRule model) { var maxPortDistanceToWater = 5; var field = model.Fields[this.Position.X, this.Position.Y]; if (field.DistanceToWater > maxPortDistanceToWater) { return(0); } var ports = model.Roads.SelectMany(b => b.Buildings).Where(b => b is Port); if (ports.Any()) { //("There can be only one port"); return(0); } return(15); }
public override double CalculateFitness(BuildingRule model) { var maxResidencesPerTavern = Position.DistanceTo(model.SettlementCenter) < 15 ? 60 : 80; var residences = model.Roads .SelectMany(b => b.Buildings) .Where(r => r.Position.DistanceTo(this.Position) <= 10) .Count(b => b is Residence); var taverns = model.Roads .SelectMany(b => b.Buildings) .Where(r => r.Position.DistanceTo(this.Position) <= 10) .Count(b => b is Tavern); if (residences / (taverns + 1) < maxResidencesPerTavern) { return(0); } return(3); }
static IRule CompileNodeForRule(string ruletext, Dictionary <int, RuleCacheItem> ruleSet) { Function Head, BuildingRule; Head = BuildingRule = new AndRule(); foreach (var item in ruletext.Split(' ')) { if (item.Contains("\"")) { var nodeToAdd = new StringRule { toMatch = item[1] };; //Comment this line for multi string rule support return(nodeToAdd); BuildingRule.AddNode(nodeToAdd); } else if (item.Contains("|")) { //Split on left and right Head = new OrRule(); Head.AddNode(BuildingRule); BuildingRule = new AndRule(); Head.AddNode(BuildingRule); } else { var childToExplore = int.Parse(item); //Check if the cached copy hasn't compiled yet and compile it if (ruleSet[childToExplore].CachedRule == null) { ruleSet[childToExplore].CachedRule = CompileNodeForRule(ruleSet[childToExplore].Text, ruleSet); } BuildingRule.AddNode(ruleSet[childToExplore].CachedRule); } } return(Head); }
public override double CalculateFitness(BuildingRule model) { var maxDistanceToCenter = 10; if (Position.DistanceTo(model.SettlementCenter) > maxDistanceToCenter) { //market is close enough to the settlement center return(0); } var buildings = model.Roads.SelectMany(b => b.Buildings).Count(); var administrations = model.Roads.SelectMany(b => b.Buildings).Count(b => b is Administration); if (buildings / (administrations + 1) < 2000) { //("No more than one administration per 2000 buildings"); return(0); } return(10); }
public override double CalculateFitness(BuildingRule model) { var minDistanceBetweenMarkets = 30; var markets = model.Roads.SelectMany(b => b.Buildings).Where(b => b != this && b is Market); if (!markets.All(m => m.Position.DistanceTo(this.Position) >= minDistanceBetweenMarkets)) { //("Other markets are too close"); return(0); } var residences = model.Roads.SelectMany(b => b.Buildings).Where(b => b is Residence); if (residences.Count(r => r.Position.DistanceTo(this.Position) <= 20) < 250) { //("Not enough residences in closest neighborhood"); return(0); } return(5); }
public override double CalculateFitness(BuildingRule model) { return(0.1); }
public async Task ReportRuleCallbackAsync(ExamineResponse examineResponse) { var updaterecord = await Context.UpdateRecords.FirstOrDefaultAsync(a => a.Id == examineResponse.SubmitDefineId); if (updaterecord == null) { throw new Exception("未找到动态记录"); } if (examineResponse.ExamineStatus == ExamineStatus.Examined) { var buildingRule = await Context.BuildingRules.FirstOrDefaultAsync(a => a.Id == examineResponse.ContentId); updaterecord.ExamineStatus = Models.ExamineStatusEnum.Approved; ReportRuleUpdateModel reportRuleUpdateModel = JsonConvert.DeserializeObject <ReportRuleUpdateModel>(updaterecord.UpdateContent); if (buildingRule == null) { buildingRule = new BuildingRule(); buildingRule.Id = examineResponse.ContentId; buildingRule.AdvanceTime = reportRuleUpdateModel.AdvanceTime; buildingRule.BeltProtectDay = reportRuleUpdateModel.BeltProtectDay; buildingRule.IsCompletenessPhone = reportRuleUpdateModel.IsCompletenessPhone; buildingRule.LiberatingEnd = reportRuleUpdateModel.LiberatingEnd; buildingRule.LiberatingStart = reportRuleUpdateModel.LiberatingStart; buildingRule.Mark = reportRuleUpdateModel.Mark; buildingRule.MaxCustomer = reportRuleUpdateModel.MaxCustomer; buildingRule.ReportedTemplate = reportRuleUpdateModel.ReportedTemplate; buildingRule.ReportTime = reportRuleUpdateModel.ReportTime; buildingRule.ValidityDay = reportRuleUpdateModel.ValidityDay; buildingRule.IsUse = reportRuleUpdateModel.IsUse; Context.Update(updaterecord); Context.Add(buildingRule); } else { buildingRule.AdvanceTime = reportRuleUpdateModel.AdvanceTime; buildingRule.BeltProtectDay = reportRuleUpdateModel.BeltProtectDay; buildingRule.IsCompletenessPhone = reportRuleUpdateModel.IsCompletenessPhone; buildingRule.LiberatingEnd = reportRuleUpdateModel.LiberatingEnd; buildingRule.LiberatingStart = reportRuleUpdateModel.LiberatingStart; buildingRule.Mark = reportRuleUpdateModel.Mark; buildingRule.MaxCustomer = reportRuleUpdateModel.MaxCustomer; buildingRule.ReportedTemplate = reportRuleUpdateModel.ReportedTemplate; buildingRule.ReportTime = reportRuleUpdateModel.ReportTime; buildingRule.ValidityDay = reportRuleUpdateModel.ValidityDay; buildingRule.IsUse = reportRuleUpdateModel.IsUse; Context.Update(updaterecord); Context.Update(buildingRule); } } else if (examineResponse.ExamineStatus == ExamineStatus.Reject) { updaterecord.ExamineStatus = Models.ExamineStatusEnum.Reject; Context.Update(updaterecord); } else { throw new Exception("审核状态不正确"); } try { Context.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } }
public void SetFitness(BuildingRule model) { Fitness = this.CalculateFitness(model); }
public abstract double CalculateFitness(BuildingRule model);