Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added iDNA 1.5/.DS_Store
Binary file not shown.
373 changes: 373 additions & 0 deletions iDNA 1.5/iDNA.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
<true/>
<key>SnapshotAutomaticallyBeforeSignificantChanges</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "1.0">
<FileBreakpoints>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "iDNA/HVSPopulationOfDna.m"
timestampString = "381583265.58348"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "112"
endingLineNumber = "112"
landmarkName = "-evolution"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "iDNA/HVSPopulationOfDna.m"
timestampString = "381583265.58348"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "132"
endingLineNumber = "132"
landmarkName = "-evolution"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "iDNA/HVSDocument.m"
timestampString = "381608092.279412"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "173"
endingLineNumber = "173"
landmarkName = "-buttonStart:"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "iDNA/HVSDocument.m"
timestampString = "381608092.279412"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "231"
endingLineNumber = "231"
landmarkName = "-buttonLoad:"
landmarkType = "5">
</FileBreakpoint>
</FileBreakpoints>
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0450"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2EEBA3FF16875CA5004EC063"
BuildableName = "iDNA.app"
BlueprintName = "iDNA"
ReferencedContainer = "container:iDNA.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2EEBA3FF16875CA5004EC063"
BuildableName = "iDNA.app"
BlueprintName = "iDNA"
ReferencedContainer = "container:iDNA.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2EEBA3FF16875CA5004EC063"
BuildableName = "iDNA.app"
BlueprintName = "iDNA"
ReferencedContainer = "container:iDNA.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2EEBA3FF16875CA5004EC063"
BuildableName = "iDNA.app"
BlueprintName = "iDNA"
ReferencedContainer = "container:iDNA.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>iDNA.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>2EEBA3FF16875CA5004EC063</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Binary file added iDNA 1.5/iDNA/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions iDNA 1.5/iDNA/HVSCellDna.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// HVSCellDna.h
// iDNA
//
// Created by VladIslav Khazov on 23.12.12.
// Copyright (c) 2012 VladIslav Khazov. All rights reserved.
//

#import <Foundation/Foundation.h>

//размерность ДНК (Значение по умолчанию)
#define sizeDNA 100 // НЕ задавать меньше 1 !

@interface HVSCellDna : NSObject

// Основной массив, создаем свойство с методами
@property NSMutableArray *DNA;
//Данное свойство будет хранить размер данной ДНК. (Можно было брать его из популяции, но мне кажется так будет доп. проверка передаваемых значений)
@property int lengthDna;

//Определяем функцию сравнения, входной параметр объект класса HVSСellDna
-(int) hammingDistance: (HVSCellDna *) otherCell;
//Мутация входящий параметр - %
-(void) mutate:(int) i;
//метод init
-(id)init;
//Свой метод init с указанной размерностью ДНК.
-(id)initWithLengthDna:(int) length;
@end
110 changes: 110 additions & 0 deletions iDNA 1.5/iDNA/HVSCellDna.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// HVSCellDna.m
// iDNA
//
// Created by VladIslav Khazov on 23.12.12.
// Copyright (c) 2012 VladIslav Khazov. All rights reserved.
//

#import "HVSCellDna.h"

@implementation HVSCellDna

//Изменяем стандартный метод init
- (id) init {
if (sizeDNA<1) {
NSAlert *myAlert = [NSAlert alertWithMessageText:NSLocalizedString(@"WARNING_DNA","ДНК не может быть меньше 1") defaultButton:NSLocalizedString(@"EXIT", "") alternateButton:nil otherButton:nil informativeTextWithFormat:@" "];
[myAlert runModal];
exit(0);
}
//вызов родительского метода
self = [super init];
if (self) {
//Создаем временный массив
NSArray *arrayCode = [NSArray arrayWithObjects:@"A", @"T", @"G", @"C", nil];
//Определяем размерность нашего массива
_DNA = [[NSMutableArray alloc] initWithCapacity:sizeDNA];
//Заполняем массив
for (int i=0; i<=sizeDNA-1; i++) {
//Добавляем объект в массив DNA, используя случайное число от 0 до 3, как индекс для массива arrayCode
[_DNA addObject:[arrayCode objectAtIndex:arc4random_uniform(4)]];
}
}
// Устанавливаем размерность данного ДНК.
[self setLengthDna:(int)sizeDNA];
return self;
}

-(id)initWithLengthDna:(int)length {
if (length<1 || length>100) {
NSAlert *myAlert = [NSAlert alertWithMessageText:NSLocalizedString(@"WARNING_DNA","ДНК не может быть меньше 1 и больше 100.") defaultButton:NSLocalizedString(@"EXIT", "") alternateButton:nil otherButton:nil informativeTextWithFormat:@" "];
[myAlert runModal];
exit(0);
}
//вызов родительского метода
self = [super init];
if (self) {
//Создаем временный массив
NSArray *arrayCode = [NSArray arrayWithObjects:@"A", @"T", @"G", @"C", nil];
//Определяем размерность нашего массива
_DNA = [[NSMutableArray alloc] initWithCapacity:length];
//Заполняем массив
for (int i=0; i<=length-1; i++) {
//Добавляем объект в массив DNA, используя случайное число от 0 до 3, как индекс для массива arrayCode
[_DNA addObject:[arrayCode objectAtIndex:arc4random_uniform(4)]];
}
}
// Устанавливаем размерность данного ДНК.
[self setLengthDna:(int)length];
return self;
}

-(int) hammingDistance: (HVSCellDna *) otherCell{
//Счетчик совпадений
int count = 0;
//Проверка размерности
if (_lengthDna != [otherCell lengthDna]) {
NSAlert *myAlert = [NSAlert alertWithMessageText:NSLocalizedString(@"WARNING_DNA_SIZE", "ДНК имеют разную размерность!") defaultButton:NSLocalizedString(@"OK", "") alternateButton:nil otherButton:nil informativeTextWithFormat:@" "];
[myAlert runModal];
return 0;
}
// [otherCell DNA] возвращает свойство второго HVSCellDna, Обращаемся к нему как к NSMutableArray
for(int i=0;i<=_lengthDna-1;i++){
//Проверяем на совпадение
if ([[otherCell DNA] objectAtIndex:i]!=[_DNA objectAtIndex:i]) {
count++;
}
}
return count;
}

-(void) mutate:(int) i{
if (i<1 || i>100) {
NSAlert *myAlert = [NSAlert alertWithMessageText:NSLocalizedString(@"WARNING_MUTATE","Указан не верный параметр 'Процента мутации'. Обе ДНК остались без изменений") defaultButton:NSLocalizedString(@"OK", "") alternateButton:nil otherButton:nil informativeTextWithFormat:@" "];
[myAlert runModal];
return;
}
// Количество элементов которые необходимо изменить в ДНК
int countMutator = _lengthDna*i/100;
//Создадим массив для хранения еще не мутировавших
NSMutableArray *arrayCheck = [[NSMutableArray alloc] initWithCapacity:_lengthDna];
for (int k=0; k<_lengthDna; k++) {
[arrayCheck addObject:[NSNumber numberWithInt:k]];
}
//Создаем временный массив видов ДНК
NSArray *arrayCode = [NSArray arrayWithObjects:@"A", @"T", @"G", @"C", nil];
// Переменная для случайного номера ДНК
int dnaIndex = 0;

//Цикл по нужному количество изменяемых элементов
for (int j=1; j<=countMutator; j++) {
//Генерим случайное число от 0 до количества еще не мутировавших элементов
dnaIndex = arc4random_uniform(_lengthDna-j+1);
//Меняем
[[self DNA] replaceObjectAtIndex:[[arrayCheck objectAtIndex:dnaIndex] intValue] withObject:[arrayCode objectAtIndex:arc4random_uniform(4)]];
// Удаляем мутировавший элемент из архива
[arrayCheck removeObjectAtIndex:dnaIndex];
}
}

@end
53 changes: 53 additions & 0 deletions iDNA 1.5/iDNA/HVSDocument.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// HVSDocument.h
// iDNA
//
// Created by VladIslav Khazov on 23.12.12.
// Copyright (c) 2012 VladIslav Khazov. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "HVSPopulationOfDna.h"
#import "HVSGenerateWindowController.h"

//Для получения сообщения из Центра уведомлений
extern NSString *const HVSMyRandomNumberNotification;

@interface HVSDocument : NSDocument {
//Определяем нашу популяцию
HVSPopulationOfDna *myPopulation;
//Флаг Паузы
BOOL flagPause;
//Окно генерации случайных чисел
HVSGenerateWindowController *generate;
}
//Свойста для работы с объектами на форме
//Текстовые поля
@property (weak) IBOutlet NSTextField *popTextSize;
@property (weak) IBOutlet NSTextField *popTextLength;
@property (weak) IBOutlet NSTextField *popTextRate;
@property (weak) IBOutlet NSTextField *popTextGoalDna;
//Слайдеры
@property (weak) IBOutlet NSSlider *popSliderSize;
@property (weak) IBOutlet NSSlider *popSliderLength;
@property (weak) IBOutlet NSSlider *popSliderRate;
//Лэйблы
@property (weak) IBOutlet NSTextField *popLabelGeneration;
@property (weak) IBOutlet NSTextField *popLabelMatch;
//Индикатор
@property (weak) IBOutlet NSLevelIndicator *popLevelMatch;
//Кнопки
@property (weak) IBOutlet NSButton *popButtonStart;
@property (weak) IBOutlet NSButton *popButtonPause;
@property (weak) IBOutlet NSButton *popButtonLoad;


//Действия
- (IBAction)buttonStart:(id)sender;
- (IBAction)buttonStartNew:(id)sender; //Будет вызываться вместо buttonStart, для генерации слуайных чисел.
- (IBAction)buttonPause:(id)sender;
- (IBAction)buttonLoad:(id)sender;
//Фоновый поток
-(void)startBackgroundEvolution;

@end
Loading