/// <summary> /// Creates a new GA object with default values. /// </summary> public GA() { InitializeComponent(); LicenseManager.Validate(this.GetType(), this); Objective = null; Scaler = new ScalingDelegate(new Scaling.LinearFitnessScaler().Scale); Selector = new SelectionDelegate(Selection.RouletteSelector.Select); Recombinator = new RecombinationDelegate(Recombination.SinglePointCrossover.Recombine); //geneDescriptors = new GeneDescriptor[1]; //geneDescriptors[0] = new BinaryGeneDescriptor(); geneDescriptor = new BinaryGeneDescriptor(); highestObjective = System.Int32.MinValue; lowestObjective = System.Int32.MaxValue; license = LicenseManager.Validate(typeof(GA), this); encodingType = defaultEncodingType; selectionMethod = defaultSelectionMethod; recombinationOperator = defaultRecombinationOperator; mutationOperator = defaultMutationOperator; //PreScaler fitnessScaling = defaultFitnessScaling; }
/// <summary> /// Get the selected simple and Genre tags and determine if there has been any changes /// </summary> private void OnOk(MultiSpinner genreSpinner, Spinner tagSpinner) { // Get the selected record from the Genre spinner. If not all of the items are selected then add an entry for each selected item to a new TagGroup List <TagGroup> selectedGroups = new List <TagGroup>(); if (genreSpinner.SelectionRecord.All(genre => genre) == false) { TagGroup group = new TagGroup() { Name = FilterManagementModel.GenreTags.Name }; selectedGroups.Add(group); // Merge the Spinner's selection record and the Genre tags into a single list and then add to the new group any tags that are selected IEnumerable <Tuple <bool, Tag> > merged = genreSpinner.SelectionRecord.Zip(FilterManagementModel.GenreTags.Tags, (x, y) => Tuple.Create(x, y)); group.Tags.AddRange(merged.Where(t => (t.Item1 == true)).Select(t => t.Item2)); } // Get the simple tag Tag newTag = (tagSpinner.SelectedItemPosition == 0) ? null : Tags.GetTagByName(tagSpinner.SelectedItem.ToString()); // Check for simple or group tag changes if ((newTag != CurrentlySelectedFilter) || (selectedGroups.Count != CurrentlySelectedTagGroups.Count) || (selectedGroups.Any(group => GroupChanged(group)) == true)) { // Update the FilterManagementModel TagGroups with the possibly updated data from the Adapter CurrentlySelectedTagGroups.Clear(); CurrentlySelectedTagGroups.AddRange(selectedGroups); SelectionDelegate?.Invoke(newTag); } }
public void RequestResourceSelection() { panelSelectImprovement.SetActive(false); panelSelectDice.SetActive(false); panelSelectCommodity.SetActive(false); ResourceClearSelection(); for (int i = 0; i < 5; i++) { buttonResources [i].onClick.RemoveAllListeners(); } buttonResources [0].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [0].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().OnResourcesChanged(ResourceType.Lumber, 1); GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdResponseToServer(); }; }); buttonResources [1].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [1].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().OnResourcesChanged(ResourceType.Brick, 1); GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdResponseToServer(); }; }); buttonResources [2].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [2].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().OnResourcesChanged(ResourceType.Wool, 1); GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdResponseToServer(); }; }); buttonResources [3].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [3].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().OnResourcesChanged(ResourceType.Grain, 1); GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdResponseToServer(); }; }); buttonResources [4].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [4].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().OnResourcesChanged(ResourceType.Ore, 1); GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdResponseToServer(); }; }); panelSelectResource.SetActive(true); gameObject.SetActive(true); }
public void RunWaitingDelegate() { if (waitingDelegate != null) { waitingDelegate(); waitingDelegate = null; } }
public void RequestResourceMonopoly() { panelSelectImprovement.SetActive(false); panelSelectDice.SetActive(false); panelSelectCommodity.SetActive(false); ResourceClearSelection(); for (int i = 0; i < 5; i++) { buttonResources [i].onClick.RemoveAllListeners(); } buttonResources [0].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [0].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedResourceMonopoly(0); }; }); buttonResources [1].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [1].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedResourceMonopoly(1); }; }); buttonResources [2].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [2].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedResourceMonopoly(2); }; }); buttonResources [3].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [3].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedResourceMonopoly(3); }; }); buttonResources [4].onClick.AddListener(delegate { ResourceClearSelection(); imgResourceSelections [4].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedResourceMonopoly(4); }; }); panelSelectResource.SetActive(true); gameObject.SetActive(true); }
public GameObject SelectFrom(List <GameObject> list, SelectionDelegate checker) { for (int i = 0; i < list.Count; i++) { if (checker(list [i])) { return(list [i]); } } return(null); }
/// <summary>フォルダ以下を圧縮</summary> /// <param name="zipFileToCreate">圧縮ファイル名(zip、exe)</param> /// <param name="directoryToZip">圧縮対象フォルダ</param> /// <param name="selectionDlgt">ファイル選択デリゲード</param> /// <param name="selectionCriteriaInfo">ファイル選択基準情報</param> /// <param name="rootPathInArchive">書庫内ルートフォルダ</param> /// <param name="enc">エンコーディング</param> /// <param name="cyp">暗号化</param> /// <param name="zipPassword">パスワード</param> /// <param name="cmpLv">圧縮レベル</param> /// <param name="selfEx">書庫形式(zip形式はnullを指定)</param> public void CreateZipFromFolder( string zipFileToCreate, string directoryToZip, SelectionDelegate selectionDlgt, object selectionCriteriaInfo, string rootPathInArchive, Encoding enc, EncryptionAlgorithm cyp, string zipPassword, CompressionLevel cmpLv, SelfExtractorFlavor?selfEx) { #region ファイル選択基準 // ファイル選択デリゲード if (selectionDlgt != null) { // 指定のデリゲード this._selectionDlgt = selectionDlgt; // ファイル選択基準情報 this._selectionCriteriaInfo = selectionCriteriaInfo; } #endregion // ZipFileを取得 ZipFile zip = this.GetZipFile( enc, cyp, zipPassword, cmpLv, selfEx); using (zip) // 使い終ったら「zip.Dispose」する。 { //// ● フォルダのアーカイブ //zip.AddDirectory(directoryToZip, rootPathInArchive); // ● ファイルを個別に追加する(UOCにて実装)。 this.CreateZipFromFolderRecursive( zip, directoryToZip, rootPathInArchive); if (selfEx == null) { // ZIPファイル zip.Save(zipFileToCreate + ".zip"); } else { // 自動解凍書庫 zip.SaveSelfExtractor( zipFileToCreate + ".exe", (SelfExtractorFlavor)selfEx); } } }
/// <summary>フォルダ以下を圧縮</summary> /// <param name="zipFileToCreate">圧縮ファイル名(zip、exe)</param> /// <param name="directoryToZip">圧縮対象フォルダ</param> /// <param name="selectionDlgt">ファイル選択デリゲード</param> /// <param name="selectionCriteriaInfo">ファイル選択基準情報</param> /// <param name="rootPathInArchive">書庫内ルートフォルダ</param> /// <param name="enc">エンコーディング</param> /// <param name="cyp">暗号化</param> /// <param name="zipPassword">パスワード</param> /// <param name="cmpLv">圧縮レベル</param> /// <param name="selfEx">書庫形式(zip形式はnullを指定)</param> public void CreateZipFromFolder( string zipFileToCreate, string directoryToZip, SelectionDelegate selectionDlgt, object selectionCriteriaInfo, string rootPathInArchive, Encoding enc, EncryptionAlgorithm cyp, string zipPassword, CompressionLevel cmpLv, SelfExtractorFlavor? selfEx) { #region ファイル選択基準 // ファイル選択デリゲード if (selectionDlgt != null) { // 指定のデリゲード this._selectionDlgt = selectionDlgt; // ファイル選択基準情報 this._selectionCriteriaInfo = selectionCriteriaInfo; } #endregion // ZipFileを取得 ZipFile zip = this.GetZipFile( enc, cyp, zipPassword, cmpLv, selfEx); using (zip) // 使い終ったら「zip.Dispose」する。 { //// ● フォルダのアーカイブ //zip.AddDirectory(directoryToZip, rootPathInArchive); // ● ファイルを個別に追加する(UOCにて実装)。 this.CreateZipFromFolderRecursive( zip, directoryToZip, rootPathInArchive); if (selfEx == null) { // ZIPファイル zip.Save(zipFileToCreate + ".zip"); } else { // 自動解凍書庫 zip.SaveSelfExtractor( zipFileToCreate + ".exe", (SelfExtractorFlavor)selfEx); } } }
public GeneticAlgorithmFinder( FitnessDelegate fitnessDelegate, MutationDelegate mutationDelegate, CrossOverDelegate crossOverDelegate, SelectionDelegate selectionDelegate, IRouteService routeService, GASettings gASettings ) { Fitness = fitnessDelegate; Mutation = mutationDelegate; Crossover = crossOverDelegate; Selection = selectionDelegate; settings = gASettings; this.routeService = routeService; }
public GameObject RandomFrom(List <GameObject> list, SelectionDelegate checker) { randomFromCache.Clear(); for (int i = 0; i < list.Count; i++) { if (checker(list[i])) { randomFromCache.Add(list[i]); } } if (randomFromCache.Count == 0) { return(null); } return(randomFromCache[random.Next(0, randomFromCache.Count)]); }
public void RequestDiceSelection() { panelSelectImprovement.SetActive(false); panelSelectResource.SetActive(false); panelSelectCommodity.SetActive(false); whiteDiceSelection = 1; redDiceSelection = 1; imgWhiteDice.sprite = Resources.Load <Sprite> ("UI/dice/dices_white_1"); imgRedDice.sprite = Resources.Load <Sprite> ("UI/dice/dices_red_1"); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdSetDice(whiteDiceSelection, redDiceSelection); GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdResponseToServer(); }; panelSelectDice.SetActive(true); gameObject.SetActive(true); }
/// <summary>ZIPファイルを解凍</summary> /// <param name="zipFileName">ZIPファイル名</param> /// <param name="directoryToUnZip">解凍先</param> /// <param name="selectionDlgt">ファイル選択デリゲード</param> /// <param name="selectionCriteriaInfo">ファイル選択基準情報</param> /// <param name="extractExistingFile">上書き時の動作</param> /// <param name="enc">エンコーディング</param> /// <param name="zipPassword">パスワード</param> public void ExtractFileFromZip( string zipFileName, string directoryToUnZip, SelectionDelegate selectionDlgt, object selectionCriteriaInfo, ExtractExistingFileAction extractExistingFile, Encoding enc, string zipPassword) { #region ファイル選択 // ファイル選択デリゲード if (selectionCriteriaInfo != null) { // 指定のデリゲード this._selectionDlgt = selectionDlgt; // ファイル選択基準情報 this._selectionCriteriaInfo = selectionCriteriaInfo; } #endregion // ZipFileを取得 ZipFile zip = this.GetZipFile(zipFileName, enc, zipPassword); using (zip) // 使い終ったら「zip.Dispose」する。 { //// ● フォルダのアーカイブ //zip.ExtractAll(directoryToUnZip, extractExistingFile); // ● ファイルを個別に追加する(UOCにて実装)。 foreach (ZipEntry ze in zip.Entries) { // 圧縮対象ファイルを選択(ファイル選択デリゲードを使用) if (this.SelectionDlgt(ze.FileName, selectionCriteriaInfo)) { // デフォルトでは、zipファイルの位置に解凍される。 ze.Extract(directoryToUnZip, extractExistingFile); } } } }
public void RequestTradeMonopoly() { panelSelectImprovement.SetActive(false); panelSelectResource.SetActive(false); panelSelectDice.SetActive(false); CommodityClearSelection(); for (int i = 0; i < 3; i++) { buttonCommodities [i].onClick.RemoveAllListeners(); } buttonCommodities [0].onClick.AddListener(delegate { CommodityClearSelection(); imgCommoditySelections[0].SetActive(true); waitingDelegate = delegate() { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedTradeMonopoly(5); }; }); buttonCommodities [1].onClick.AddListener(delegate { CommodityClearSelection(); imgCommoditySelections[1].SetActive(true); waitingDelegate = delegate() { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedTradeMonopoly(6); }; }); buttonCommodities [2].onClick.AddListener(delegate { CommodityClearSelection(); imgCommoditySelections[2].SetActive(true); waitingDelegate = delegate() { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdPlayedTradeMonopoly(7); }; }); panelSelectCommodity.SetActive(true); gameObject.SetActive(true); }
public void RequestImprovementSelection(bool canTrade, bool canPolitics, bool canScience) { panelSelectResource.SetActive(false); panelSelectDice.SetActive(false); panelSelectCommodity.SetActive(false); ImprovementClearSelection(); for (int i = 0; i < 3; i++) { buttonImprovements [i].interactable = true; buttonImprovements [i].onClick.RemoveAllListeners(); } if (canTrade) { buttonImprovements [0].onClick.AddListener(delegate { ImprovementClearSelection(); imgImprovementSelections [0].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdRequestDrawProgressCard(0); }; }); } else { buttonImprovements [0].interactable = false; } if (canPolitics) { buttonImprovements [1].onClick.AddListener(delegate { ImprovementClearSelection(); imgImprovementSelections [1].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdRequestDrawProgressCard(1); }; }); } else { buttonImprovements [1].interactable = false; } if (canScience) { buttonImprovements [2].onClick.AddListener(delegate { ImprovementClearSelection(); imgImprovementSelections [2].SetActive(true); waitingDelegate = delegate { GameObject.Find("Local Player Panel").GetComponent <Player> ().CmdRequestDrawProgressCard(2); }; }); } else { buttonImprovements [2].interactable = false; } panelSelectImprovement.SetActive(true); gameObject.SetActive(true); }
public Node(SelectionDelegate selectionDelegate) : this(string.Empty) { Delegate = selectionDelegate; }
/// <summary> /// Creates a new GA object with default values. /// </summary> public GA() { InitializeComponent(); LicenseManager.Validate( this.GetType(), this ); Objective = null; Scaler = new ScalingDelegate ( new Scaling.LinearFitnessScaler().Scale ); Selector = new SelectionDelegate ( Selection.RouletteSelector.Select ); Recombinator= new RecombinationDelegate ( Recombination.SinglePointCrossover.Recombine ); //geneDescriptors = new GeneDescriptor[1]; //geneDescriptors[0] = new BinaryGeneDescriptor(); geneDescriptor = new BinaryGeneDescriptor(); highestObjective = System.Int32.MinValue; lowestObjective = System.Int32.MaxValue; license = LicenseManager.Validate(typeof(GA), this); encodingType = defaultEncodingType; selectionMethod = defaultSelectionMethod; recombinationOperator = defaultRecombinationOperator; mutationOperator = defaultMutationOperator; //PreScaler fitnessScaling = defaultFitnessScaling; }