public Gene Mutate(MutationParams mutationParams) { if (!Utility.flipCoin(mutationParams.shouldMutate.probability)) { return(this); } if (Utility.flipCoin(mutationParams.axis.probability)) { this.axis = Utility.genAxis(); } if (Utility.flipCoin(mutationParams.enableMode.probability)) { this.enableMode = (EnableMode)Utility.genInt((int)EnableMode.NumEnableModes); } if (Utility.flipCoin(mutationParams.heartBeat.probability)) { this.heartBeat = Utility.nudgeFloat(this.heartBeat, heartBeatRange, mutationParams.heartBeat.amount); } if (Utility.flipCoin(mutationParams.contractTime.probability)) { this.contractTime = Utility.nudgeFloat(this.contractTime, contractTimeRange, mutationParams.contractTime.amount); } if (Utility.flipCoin(mutationParams.extensionDistance.probability)) { this.extensionDistance = Utility.nudgeFloat(this.extensionDistance, extensionDistanceRange, mutationParams.extensionDistance.amount); } return(this); }
public async Task <PagedList <Mutation> > GetMutationsForUserAccount(MutationParams mutationParams) { var mutations = _context.Mutations .Where(m => m.UserId == mutationParams.UserId && m.AccountId == mutationParams.AccountId) .AsQueryable(); if (mutationParams.MinAmount != MutationParams.cMinAmount || mutationParams.MaxAmount != MutationParams.cMaxAmount) { mutations = mutations.Where(m => (m.Amount >= mutationParams.MinAmount) && (m.Amount <= mutationParams.MaxAmount)); } if (!(mutationParams.MinDate == null || mutationParams.MinDate.CompareTo(DateTime.MinValue) == 0)) { mutations = mutations.Where(m => m.Created >= mutationParams.MinDate); } if (!(mutationParams.MaxDate == null || mutationParams.MaxDate.CompareTo(DateTime.MinValue) == 0)) { mutations = mutations.Where(m => m.Created <= mutationParams.MaxDate); } var omutations = mutations.OrderByDescending(m => m.Id); return(await PagedList <Mutation> .CreateAsync(omutations, mutationParams.PageNumber, mutationParams.PageSize)); }
public async Task <IActionResult> GetMutationsForUserAccount(int userId, int accountId, MutationParams mutationParams) { var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (currentUserId != userId) { return(Unauthorized()); } var account = await _repo.GetAccount(accountId); if (account == null || account.UserId != userId) { return(Unauthorized()); } var user = await _repo.GetUser(userId); mutationParams.UserId = userId; mutationParams.AccountId = accountId; var pgMutationsFromRepo = await _repo.GetMutationsForUserAccount(mutationParams); var accDisply = _map.Map <AccountForDetailedDto>(account); var mutations = _map.Map <ICollection <MutationForListDto> >(pgMutationsFromRepo); Response.AddPagination(pgMutationsFromRepo.CurrentPage, pgMutationsFromRepo.PageSize, pgMutationsFromRepo.TotalCount, pgMutationsFromRepo.TotalPages); return(Ok(new MutationForPageDto { Account = accDisply, Mutations = mutations })); }
public Gene Mutate(MutationParams mutationParams) { return(this); }
/* p2 fitness > p1fitness */ public void SetParents( ProunGenome p1, ProunGenome p2, float p1Fitness, float p2Fitness, MutationParams mutationParams) { int p1Size = p1.body.Length; int p2Size = p2.body.Length; int smallerSize = p2Size > p1Size ? p1Size : p2Size; int largerSize = p1Size > p2Size ? p1Size : p2Size; float fitnessRatio = p2Fitness / (p1Fitness + p2Fitness); int newSize = 0; NodeGene[] _newBody = new NodeGene[largerSize]; for (int i = 0; i < smallerSize; i++, newSize++) { _newBody [i] = Utility.genFloat() < fitnessRatio ? p2.body [i] : p1.body [i]; } if (p2Size > p1Size) { for (int i = smallerSize; i < largerSize; i++, newSize++) { _newBody [i] = p2.body [i]; } } NodeGene[] newBody = new NodeGene[newSize]; for (int i = 0; i < newSize; i++) { newBody [i] = _newBody [i]; newBody [i].index = i; } AdjacencyMatrix <MuscleGene> newMind = new AdjacencyMatrix <MuscleGene> (newSize); for (int i = 0; i < smallerSize; i++) { for (int j = 0; j < smallerSize; j++) { MuscleGene muscleGene = p1.mind.GetNeighbor(i, j); if (muscleGene != null) { newMind.SetNeighbor(i, j, muscleGene.Disable()); } } } for (int i = 0; i < p2Size; i++) { for (int j = 0; j < p2Size; j++) { MuscleGene muscleGene = p2.mind.GetNeighbor(i, j); if (muscleGene != null) { newMind.SetNeighbor(i, j, (MuscleGene)muscleGene.Mutate(mutationParams.muscleGeneMutationParams)); } } } this.body = newBody; this.mind = newMind; }
public async Task <PagedList <Mutation> > GetAccountMutationsForUser(int userId, int accountId, MutationParams mp) { var mutations = _context.Mutations .Where(m => m.UserId == userId && m.AccountId == accountId) .OrderByDescending(m => m.Created); return(await PagedList <Mutation> .CreateAsync(mutations, mp.PageNumber, mp.PageSize)); }