Ejemplo n.º 1
0
        private void OperatorGraphView_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Effect != DragDropEffects.None)
            {
                IOperator op = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IOperator;
                if (e.Effect.HasFlag(DragDropEffects.Copy))
                {
                    op = (IOperator)op.Clone();
                }
                IOperatorShapeInfo shapeInfo = OperatorShapeInfoFactory.CreateOperatorShapeInfo(op);
                Point  mouse      = new Point(MousePosition.X, MousePosition.Y);
                Point  screen     = this.graphVisualizationInfoView.PointToScreen(new Point(0, 0));
                Point  control    = new Point(mouse.X - screen.X, mouse.Y - screen.Y);
                PointF worldPoint = this.graphVisualizationInfoView.Controller.View.ViewToWorld(control);

                if (worldPoint.X < 0)
                {
                    worldPoint.X = 0;
                }
                if (worldPoint.Y < 0)
                {
                    worldPoint.Y = 0;
                }

                shapeInfo.Location = Point.Round(worldPoint);
                this.VisualizationInfo.AddShapeInfo(op, shapeInfo);
            }
        }
Ejemplo n.º 2
0
 private void graphTreeView_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Effect != DragDropEffects.None)
     {
         IOperator op = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IOperator;
         if (e.Effect.HasFlag(DragDropEffects.Copy))
         {
             op = (IOperator)op.Clone();
         }
         TreeNode        node    = graphTreeView.GetNodeAt(graphTreeView.PointToClient(new Point(e.X, e.Y)));
         IValueParameter opParam = GetOperatorParameterTag(node);
         opParam.Value = op;
     }
 }
Ejemplo n.º 3
0
        public static void FromOperator(IOperator op)
        {
            var permList = new List <List <IObject> >();

            foreach (Term variable in op.Terms)
            {
                permList.Add(typeDict[variable.Type] as List <IObject>);
            }

            foreach (var combination in EnumerableExtension.GenerateCombinations(permList))
            {
                // Add bindings
                var opClone            = op.Clone() as Operator;
                var termStringList     = from term in opClone.Terms select term.Variable;
                var constantStringList = from objConst in combination select objConst.Name;
                opClone.AddBindings(termStringList.ToList(), constantStringList.ToList());
                var legal = true;
                foreach (var precon in opClone.Preconditions)
                {
                    if (!NonStaticPredicates.Contains(precon.Name))
                    {
                        // this predicate is static
                        if (!Init.Contains(precon))
                        {
                            legal = false;
                            break;
                        }
                    }
                }
                if (!legal)
                {
                    continue;
                }

                // this ensures that this ground operator has a unique ID
                var groundOperator = new Operator(opClone.Name, opClone.Terms, opClone.Bindings, opClone.Preconditions, opClone.Effects);

                if (GroundLibrary.ContainsKey(groundOperator.ID))
                {
                    throw new System.Exception();
                }

                GroundActions.Add(groundOperator as IOperator);
                GroundLibrary[groundOperator.ID] = groundOperator;
            }
        }
        public static List <IOperator> FromOperatorWithReturn(IOperator op)
        {
            var listToReturn = new List <IOperator>();
            var permList     = new List <List <string> >();

            foreach (Term variable in op.Terms)
            {
                permList.Add(TypeDict[variable.Type] as List <string>);
            }

            foreach (var combination in EnumerableExtension.GenerateCombinations(permList))
            {
                // Add bindings
                var opClone            = op.Clone() as Operator;
                var termStringList     = from term in opClone.Terms select term.Variable;
                var constantStringList = combination;

                opClone.AddBindings(termStringList.ToList(), constantStringList.ToList());

                if (!opClone.NonEqualTermsAreNonequal())
                {
                    continue;
                }

                //Debug.Log("operator: " + opClone.ToString());

                // this ensures that this ground operator has a unique ID
                var groundOperator = new Operator(opClone.Name, opClone.Terms, opClone.Bindings, opClone.Preconditions, opClone.Effects);

                if (GroundActionFactory.GroundActions.Contains(groundOperator))
                {
                    continue;
                }

                if (GroundLibrary.ContainsKey(groundOperator.ID))
                {
                    throw new System.Exception();
                }

                InsertOperator(groundOperator as IOperator);
                listToReturn.Add(groundOperator as IOperator);
            }

            return(listToReturn);
        }