Пример #1
0
        public GuidelinePool(Monsters monsters, Map currentMap, Delegate callback, AreaManager areaManager, int maxMonsters, int maxItens, double hordesPercentage)
        {
            this.monsters = monsters;
            this.callback = callback;

            this.MaxMonsters      = maxMonsters;
            this.MaxItens         = maxItens;
            this.HordesPercentage = hordesPercentage;

            originalMap = currentMap.CloneJson() as Map;

            InitialPopulation   = 30;
            GenerationLimit     = 50;
            MutationPercentage  = 0.4;
            CrossOverPercentage = 0.8;
            ElitismPercentage   = 10;

            running     = false;
            HasSolution = false;

            cells = originalMap.SpawnCells;

            fitness = new Guideline(cells, areaManager, MaxMonsters, MaxItens, HordesPercentage)
            {
                MaxItemsLever      = LeverMaxItem,
                MaxMonstersLever   = LeverMaxMonster,
                AmountHordesLever  = LeverAmountHordes,
                DangerLever        = LeverDanger,
                AccessibilityLever = LeverAccessibility
            };

            //we can create an empty population as we will be creating the
            //initial solutions manually.
            population = new Population(InitialPopulation, cells.Count * ChromosomeUtils.NUMBER_GENES, true, true, ParentSelectionMethod.FitnessProportionateSelection);
        }
Пример #2
0
        public ActionResult New(GenGuidelineViewModel gg)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Guideline guideline = new Guideline
                    {
                        Varsta = gg.Varsta,
                        Mesaj  = gg.Mesaj,
                    };
                    db.Guidelines.Add(guideline);

                    GenFilm gen = new GenFilm
                    {
                        Nume      = gg.Nume,
                        Guideline = guideline
                    };
                    db.GenFilme.Add(gen);

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(gg));
            }
            catch (Exception e) { return(View(gg)); }
        }
        private static void ParseBlockElement(XElement blockElement, Phase phase, Guideline guideline)
        {
            // Generate the appropriate block.
            var block = GenerateBlockOfAppropriateType(blockElement, phase);

            // Add the common properties for this block.
            if (block is SummaryBlock)
            {
                AddCommonProperties(blockElement, block as SummaryBlock);
            }
            else
            {
                AddCommonProperties(blockElement, block);
            }

            // If block is assessment block, add assessment type.
            if (block is AssessmentBlock)
            {
                var            assessmentTypeString = blockElement.Attribute("AssessmentType")?.Value;
                AssessmentType assessmentType;
                var            successful = Enum.TryParse(assessmentTypeString, out assessmentType);
                if (successful)
                {
                    ((AssessmentBlock)block).AssessmentType = assessmentType;
                }
            }

            // Add block links.
            var linksElement = blockElement.Descendants("Links").FirstOrDefault();

            if (linksElement != null)
            {
                foreach (var linkElement in linksElement.Descendants("Link"))
                {
                    ParseLinkElement(linkElement, block);
                }
            }

            // Add block activities.
            var activitiesElement = blockElement.Descendants("Activities").FirstOrDefault();

            if (activitiesElement != null)
            {
                foreach (var activityElement in activitiesElement.Descendants("Activity"))
                {
                    // Generate the BlockActivityData for this element.
                    var blockActivityData = new BlockActivityData(block);

                    // Generate the common properties for this BlockActivityData.
                    AddCommonProperties(activityElement, blockActivityData);

                    // Add this activity data to the block.
                    block.BlockActivities.Add(blockActivityData);
                }
            }

            // Add this block to the phase.
            phase.Blocks.Add(block);
            guideline.LinkManager.Register(block);
        }
Пример #4
0
 public CriterionContentPage(Guideline guideline)
 {
     InitializeComponent();
     Title      = guideline.Heading;
     _criterion = guideline.Criterion;
     CriterionListView.ItemsSource = Criterion;
 }
        public async Task <Guideline> ParseGuidelineXmlAsync(string guidelineXml)
        {
            // Load the guideline element data.
            var guideLineElement = XElement.Parse(guidelineXml);

            // Retrieve the data from that guideline elements.
            var guideline = new Guideline();

            // Use reflection to add common properties.
            AddCommonProperties(guideLineElement, guideline);

            // Add phases.
            var phaseElements = guideLineElement.Descendants("Phase");

            foreach (var phaseElement in phaseElements)
            {
                ParsePhase(guideline, phaseElement);
            }

            // Identify initial phase, and set this as the phase.
            var entryPhaseIdentifier = guideLineElement.Attribute("EntryPhaseId")?.Value;
            var entryPhase           = guideline.Phases.FirstOrDefault(phase => string.Compare(phase.Identifier, entryPhaseIdentifier, StringComparison.OrdinalIgnoreCase) == 0);

            guideline.EntryPhase = entryPhase ?? guideline.Phases.FirstOrDefault();

            return(guideline);
        }
Пример #6
0
 void Ruler_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (!Container.IsProtected)
     {
         Point p = Container.GetRelativPosition(e);
         CaptureMouse();
         _localGuide = Container.CreateGuide(p, RulerOrientation.Diagonal);
     }
 }
Пример #7
0
 public void Include(ConstraintLayout constraintLayout, Guideline guideline)
 {
     constraintLayout = new ConstraintLayout(null);
     constraintLayout = new ConstraintLayout(null, null);
     constraintLayout = new ConstraintLayout(null, null, 1);
     guideline        = new Guideline(null);
     guideline        = new Guideline(null, null);
     guideline        = new Guideline(null, null, 1);
     guideline        = new Guideline(null, null, 1, 1);
 }
Пример #8
0
 void Ruler_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (_localGuide != null && !Container.IsProtected)
     {
         Point p = Container.GetRelativPosition(e);
         ReleaseMouseCapture();
         Container.FinalizeGuide(_localGuide, p);
         _localGuide = null;
     }
 }
Пример #9
0
        public void MoveGuide(Guideline line, Point p)
        {
            if (!oldShowMousePosition.HasValue)
            {
                oldShowMousePosition = ShowMousePosition;
                ShowMousePosition    = false;
            }

            line.SetPixel(p);
            RefreshGuides();
        }
Пример #10
0
        private bool IsAdjacent(Guideline gl1, Guideline gl2, Size size)
        {
            if (gl1 == null || gl2 == null)
            {
                return(false);
            }

            double distnace = Guideline.Distance(gl1, gl2);
            double length   = gl1.IsVertical ? size.Width : size.Height;

            return(DoubleEx.EpsilonEqauls(distnace, length));
        }
Пример #11
0
        void DrawingCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.Focus();

            if (e.ChangedButton == MouseButton.Left)
            {
                if (e.ClickCount == 2)
                {
                    HandleDoubleClick(e);                            // special case for GraphicsText
                }
                else
                {
                    Point loc = e.GetPosition(this);

                    if (CurrentRuler.IsSnapping)
                    {
                        CurrentSnapPosition = new Point(-1, -1);

                        Point snap = new Point(loc.X, loc.Y);

                        if (CurrentRuler.GuideManager.Intersection_GetNearst(ref snap))
                        {
                            CurrentSnapPosition = snap;
                            CurrentPosition     = loc;
                            CurrentTool.OnMouseDown(this, CurrentSnapPosition);
                            return;
                        }

                        Guideline gl = CurrentRuler.GuideManager.GetSnapGuide(loc);
                        if (gl != null)
                        {
                            gl.GetNearestPos(ref snap, CurrentRuler.dPicCapture);
                            CurrentSnapPosition = snap;
                            CurrentPosition     = loc;
                            CurrentTool.OnMouseDown(this, CurrentSnapPosition);
                            return;
                        }
                    }
                    CurrentPosition = loc;
                    CurrentTool.OnMouseDown(this, CurrentPosition);
                }
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                //CurrentRuler.IsOnGuide();
                //show guide menu
                //CurrentRuler.ContextMenu.PlacementTarget = CurrentRuler;
                //CurrentRuler.ContextMenu.IsOpen = true;
                this.ContextMenu.IsOpen = true;
            }

            e.Handled = true;
        }
Пример #12
0
        public void FinalizeGuide(Guideline line, Point p)
        {
            line.SetPixel(p);
            GuideManager.Intersection_Calculate();
            RefreshGuides();

            if (oldShowMousePosition.HasValue)
            {
                ShowMousePosition    = oldShowMousePosition.Value;
                oldShowMousePosition = null;
            }
        }
Пример #13
0
 public ActionResult Edit(int?id)
 {
     if (id.HasValue)
     {
         Guideline g = db.Guidelines.Find(id);
         if (g == null)
         {
             return(HttpNotFound("Nu am putut găsi Guideline cu Id-ul " + id.ToString()));
         }
         return(View(g));
     }
     return(HttpNotFound("Lipsește parametrul Id al Guideline-ului!"));
 }
Пример #14
0
        public ActionResult Delete(int id)
        {
            GenFilm   gen       = db.GenFilme.Find(id);
            Guideline guideline = db.Guidelines.Find(gen.Guideline.Id);

            if (gen != null)
            {
                db.GenFilme.Remove(gen);
                db.Guidelines.Remove(guideline);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(HttpNotFound("Nu s-a găsit genul filmului cu id-ul " + id.ToString() + "!"));
        }
Пример #15
0
        void Ruler_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (Container.IsProtected)
            {
                return;
            }

            //Point p = Container.GetRelativPosition(e);
            CaptureMouse();

            Point pt = e.GetPosition(this);

            _localGuide = GetGuide(pt);
        }
Пример #16
0
        public void Parse()
        {
            var matchedGuidelines = new Guideline[]
            {
                new Guideline(1.5, GuidelineColor.Green),
                new Guideline(3.2, GuidelineColor.Yellow),
                new Guideline(4.7, GuidelineColor.Orange),
                new Guideline(6.0, GuidelineColor.Green),
                new Guideline(7.25, GuidelineColor.Green),
                new Guideline(8.112, GuidelineColor.Yellow),
            };
            var collection = GuidelineCollection.Parse("1.5~1~3.2~0.9~4.7~0.8~6~1~7.25~1~8.112~0.9");

            for (int i = 0; i < matchedGuidelines.Length; i++)
            {
                Assert.IsTrue(collection[i] == matchedGuidelines[i]);
            }
        }
Пример #17
0
        public ActionResult Delete(int id)
        {
            Guideline guideline = db.Guidelines.Find(id);

            if (guideline != null)
            {
                List <GenFilm> genuri = db.GenFilme.ToList();
                foreach (var gen in genuri)
                {
                    if (gen.Guideline.Id == id)
                    {
                        db.GenFilme.Remove(gen);
                    }
                }
                db.Guidelines.Remove(guideline);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(HttpNotFound("Nu s-a găsit Guideline cu id-ul " + id.ToString() + "!"));
        }
Пример #18
0
        public IEnumerable <Guideline> GetSnappedGuidelines(IGuideProvider target)
        {
            foreach (IGuideProvider provider in Items.Except(new[] { target }))
            {
                if (provider is FrameworkElement frameworkElement &&
                    !frameworkElement.IsVisible)
                {
                    continue;
                }

                foreach (Guideline gl in provider.GetGuidableLines()
                         .Where(gl =>
                {
                    return(target.GetGuidableLines()
                           .Count(tGl =>
                    {
                        double length = Guideline.Distance(gl, tGl);

                        if (length == -1)
                        {
                            return false;
                        }

                        if (length <= this.Fit(SnapThreshold))
                        {
                            gl.SnappedGuideline = tGl;
                            return true;
                        }

                        return false;
                    }) > 0);
                }).
                         OrderBy(gl =>
                {
                    return(Guideline.Distance(gl, gl.SnappedGuideline));
                }))
                {
                    yield return(gl);
                }
            }
        }
Пример #19
0
        void Ruler_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (Container.IsProtected)
            {
                return;
            }

            if (_localGuide != null)
            {
                ReleaseMouseCapture();

                Point pt = e.GetPosition(this);

                if (PtInDelta(pt))
                {
                    Container.FinalizeGuide(_localGuide, pt);
                }
                //else
                _localGuide = null;
            }
        }
Пример #20
0
        void DrawingCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            Point loc = e.GetPosition(this);

            //CurrentUnityPosition = Container.ConvertToUnity(CurrentPosition);

            if (e.MiddleButton == MouseButtonState.Released && e.RightButton == MouseButtonState.Released)
            {
                if (CurrentRuler.IsSnapping)
                {
                    CurrentSnapPosition = new Point(-1, -1);

                    Point snap = new Point(loc.X, loc.Y);

                    if (CurrentRuler.GuideManager.Intersection_GetNearst(ref snap))
                    {
                        CurrentSnapPosition = snap;
                        CurrentPosition     = loc;
                        CurrentTool.OnMouseMove(this, CurrentSnapPosition, e.LeftButton, e.RightButton);
                        return;
                    }

                    Guideline gl = CurrentRuler.GuideManager.GetSnapGuide(loc);
                    if (gl != null)
                    {
                        gl.GetNearestPos(ref snap, CurrentRuler.dPicCapture);
                        CurrentSnapPosition = snap;
                        CurrentPosition     = loc;
                        CurrentTool.OnMouseMove(this, CurrentSnapPosition, e.LeftButton, e.RightButton);
                        return;
                    }
                }
                CurrentPosition = loc;
                CurrentTool.OnMouseMove(this, CurrentPosition, e.LeftButton, e.RightButton);
            }
            else
            {
                this.Cursor = Cursors.Arrow;
            }
        }
Пример #21
0
 public ActionResult Edit(int id, Guideline guideline)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Guideline g = db.Guidelines.Find(id);
             if (TryUpdateModel(g))
             {
                 g.Varsta = guideline.Varsta;
                 g.Mesaj  = guideline.Mesaj;
                 db.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         return(View(guideline));
     }
     catch (Exception e)
     {
         return(View(guideline));
     }
 }
        private static void ParsePhase(Guideline guideline, XElement phaseElement)
        {
            // Generate a new phase for the element.
            var phase = new Phase(guideline);

            // Add the common properties.
            AddCommonProperties(phaseElement, phase);

            // Go through the blocks contained in this phase.
            foreach (var blockElement in phaseElement.Descendants("Block"))
            {
                ParseBlockElement(blockElement, phase, guideline);
            }

            // Add the entry block to the phase.
            var entryBlockIdentifier = phaseElement.Attribute("EntryBlockId")?.Value;
            var identifiedBlock      = phase.Blocks.FirstOrDefault(block => string.Compare(block.Identifier, entryBlockIdentifier, StringComparison.CurrentCultureIgnoreCase) == 0);

            phase.EntryBlock = identifiedBlock ?? phase.Blocks.First();

            // Add the phase to the guideline.
            guideline.Phases.Add(phase);
            guideline.LinkManager.Register(phase);
        }
Пример #23
0
        void DrawingCanvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                Point loc = e.GetPosition(this);

                if (CurrentRuler.IsSnapping)
                {
                    CurrentSnapPosition = new Point(-1, -1);

                    Point snap = new Point(loc.X, loc.Y);

                    if (CurrentRuler.GuideManager.Intersection_GetNearst(ref snap))
                    {
                        CurrentSnapPosition = snap;
                        CurrentPosition     = loc;
                        CurrentTool.OnMouseUp(this, CurrentSnapPosition);
                        return;
                    }

                    Guideline gl = CurrentRuler.GuideManager.GetSnapGuide(loc);
                    if (gl != null)
                    {
                        gl.GetNearestPos(ref snap, CurrentRuler.dPicCapture);
                        CurrentSnapPosition = snap;
                        CurrentPosition     = loc;
                        CurrentTool.OnMouseUp(this, CurrentSnapPosition);
                        return;
                    }
                }
                CurrentPosition = loc;
                CurrentTool.OnMouseUp(this, CurrentPosition);

                //CurrentTool.OnMouseUp(this, e);
            }
        }
Пример #24
0
 public ActionResult Edit(int id, GenFilm gen)
 {
     try
     {
         if (ModelState.IsValid)
         {
             GenFilm   GenFilm = db.GenFilme.Find(id);
             Guideline g       = db.Guidelines.Find(gen.Guideline.Id);
             if (TryUpdateModel(GenFilm))
             {
                 GenFilm.Nume = gen.Nume;
                 g.Varsta     = gen.Guideline.Varsta;
                 g.Mesaj      = gen.Guideline.Mesaj;
                 db.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         return(View(gen));
     }
     catch (Exception e)
     {
         return(View(gen));
     }
 }
Пример #25
0
        public ResponseObject <bool> CreateGuideline(GuidelineAPIViewModel model)
        {
            try
            {
                var guidelineRepo = DependencyUtils.Resolve <IGuidelineRepository>();
                var guideline     = new Guideline();

                guideline.ServiceItemId = model.ServiceItemId;
                guideline.GuidelineName = model.GuidelineName;
                guideline.CreateDate    = DateTime.UtcNow.AddHours(7);
                guideline.UpdateDate    = DateTime.UtcNow.AddHours(7);
                guidelineRepo.Add(guideline);
                guidelineRepo.Save();
                return(new ResponseObject <bool> {
                    IsError = false, SuccessMessage = "Tạo hướng dẫn thành công!", ObjReturn = true
                });
            }
            catch (Exception e)
            {
                return(new ResponseObject <bool> {
                    IsError = true, WarningMessage = "Xóa hướng dẫn thất bại!", ObjReturn = false, ErrorMessage = e.ToString()
                });
            }
        }
Пример #26
0
 public GuidelineNameChange(Guideline target, string value)
 {
     _target = target;
     _value  = value;
 }
Пример #27
0
 public GuidelineAngleChange(Guideline target, float value)
 {
     _target = target;
     _value  = value;
 }
Пример #28
0
 public GuidelineIsSelectedChange(Guideline target, bool value)
 {
     _target = target;
     _value  = value;
 }
Пример #29
0
 public DefaultGuidelineRunner(Guideline guideline, IEventAggregator eventAggregator)
 {
     _guideline       = guideline;
     _eventAggregator = eventAggregator;
 }
Пример #30
0
        private void MarginSnap(ref Thickness margin)
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                Storyboard.GuideLayer.ClearSnappedGuidelines();
                return;
            }

            var bound   = GetParentRenderBound();
            var padding = GetPadding(Parent.Element);

            Size parentSize = bound.Size;
            Size size       = AdornedElement.RenderSize;

            bool allowVertical   = true;
            bool allowHorizontal = true;

            if (Parent is IStackLayout)
            {
                var stackPanel = Parent.Element as StackPanel;

                allowVertical =
                    (stackPanel.Orientation == Orientation.Horizontal);

                allowHorizontal =
                    (stackPanel.Orientation == Orientation.Vertical);
            }

            Guideline guidedLeft   = null;
            Guideline guidedTop    = null;
            Guideline guidedRight  = null;
            Guideline guidedBottom = null;

            foreach (Guideline item in Storyboard.GuideLayer.InvalidateSnappedGuidelines(this))
            {
                bool awHozitonal = false;
                bool awVertical  = false;

                Point pRelative = Storyboard.TranslatePoint(item.Point1, Parent.Element);
                GuidelineDirection direction = item.SnappedGuideline.Direction;

                // 대칭 가이드라인 탐색
                switch (direction)
                {
                case GuidelineDirection.Left:
                    if (guidedRight == null || IsAdjacent(guidedRight, item, size))
                    {
                        guidedLeft  = item;
                        awHozitonal = true;
                    }
                    break;

                case GuidelineDirection.Top:
                    if (guidedBottom == null || IsAdjacent(guidedBottom, item, size))
                    {
                        guidedTop  = item;
                        awVertical = true;
                    }
                    break;

                case GuidelineDirection.Right:
                    if (guidedLeft == null || IsAdjacent(guidedLeft, item, size))
                    {
                        guidedRight = item;
                        awHozitonal = true;
                    }
                    break;

                case GuidelineDirection.Bottom:
                    if (guidedTop == null || IsAdjacent(guidedTop, item, size))
                    {
                        guidedBottom = item;
                        awVertical   = true;
                    }
                    break;
                }

                // 마진 처리
                switch (direction)
                {
                case GuidelineDirection.Left:
                case GuidelineDirection.Right:
                    if (!awHozitonal || !allowHorizontal)
                    {
                        continue;
                    }

                    switch (ClipData.HorizontalAlignment)
                    {
                    case HorizontalAlignment.Left:
                        margin.Left = pRelative.X - padding.Left;
                        if (direction == GuidelineDirection.Right)
                        {
                            margin.Left -= size.Width;
                        }

                        margin.Right = Math.Min(parentSize.Width - RenderSize.Width - margin.Left, 0);
                        break;

                    case HorizontalAlignment.Right:
                        margin.Right = parentSize.Width - pRelative.X - size.Width + padding.Right;
                        if (direction == GuidelineDirection.Right)
                        {
                            margin.Right += size.Width;
                        }

                        margin.Left = Math.Min(parentSize.Width - RenderSize.Width - margin.Right, 0);
                        break;

                    case HorizontalAlignment.Center:
                        margin.Left = pRelative.X - parentSize.Width / 2 + size.Width / 2 - padding.Left;
                        if (direction == GuidelineDirection.Right)
                        {
                            margin.Left -= size.Width;
                        }
                        margin.Right = -margin.Left;
                        break;

                    case HorizontalAlignment.Stretch:
                        if (direction == GuidelineDirection.Left)
                        {
                            margin.Left  = pRelative.X - padding.Left;
                            margin.Right = parentSize.Width - margin.Left - size.Width;
                        }
                        else
                        {
                            margin.Right = parentSize.Width - pRelative.X + padding.Right;
                            margin.Left  = parentSize.Width - margin.Right - size.Width;
                        }
                        break;
                    }
                    break;

                case GuidelineDirection.Top:
                case GuidelineDirection.Bottom:
                    if (!awVertical || !allowVertical)
                    {
                        continue;
                    }

                    switch (ClipData.VerticalAlignment)
                    {
                    case VerticalAlignment.Top:
                        margin.Top = pRelative.Y;
                        if (direction == GuidelineDirection.Bottom)
                        {
                            margin.Top -= size.Height;
                        }

                        margin.Bottom = Math.Min(parentSize.Height - RenderSize.Height - margin.Top, 0);
                        break;

                    case VerticalAlignment.Bottom:
                        margin.Bottom = parentSize.Height - pRelative.Y - size.Height;
                        if (direction == GuidelineDirection.Bottom)
                        {
                            margin.Bottom += size.Height;
                        }

                        margin.Top = Math.Min(parentSize.Height - RenderSize.Height - margin.Bottom, 0);
                        break;

                    case VerticalAlignment.Center:
                        margin.Top = pRelative.Y - parentSize.Height / 2 + size.Height / 2;
                        if (direction == GuidelineDirection.Bottom)
                        {
                            margin.Top -= size.Height;
                        }
                        margin.Bottom = -margin.Top;
                        break;

                    case VerticalAlignment.Stretch:
                        if (direction == GuidelineDirection.Top)
                        {
                            margin.Top    = pRelative.Y;
                            margin.Bottom = parentSize.Height - margin.Top - size.Height;
                        }
                        else
                        {
                            margin.Bottom = parentSize.Height - pRelative.Y;
                            margin.Top    = parentSize.Height - margin.Bottom - size.Height;
                        }
                        break;
                    }
                    break;
                }

                item.IsVisible = true;
            }
        }