public void GenBFSTreeFromArcLoft()
            {
                Surface testsweep = UnfoldTestUtils.SetupArcLoft();

                var surfaces = new List <Surface>()
                {
                    testsweep
                };
                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();


                var graph = ModelTopology.GenerateTopologyFromSurfaces(trisurfaces);

                List <Object> face_objs = trisurfaces.Select(x => x as Object).ToList();

                UnfoldTestUtils.GraphHasVertForEachFace(graph, face_objs);

                var    nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);
                object tree       = nodereturn;

                var casttree = tree as List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> >;

                UnfoldTestUtils.GraphHasVertForEachFace(casttree, face_objs);
                UnfoldTestUtils.AssertAllFinishingTimesSet(graph);

                var sccs = GraphUtilities.TarjansAlgo <EdgeLikeEntity, FaceLikeEntity> .CycleDetect(casttree, GraphUtilities.EdgeType.Tree);

                UnfoldTestUtils.IsAcylic <EdgeLikeEntity, FaceLikeEntity>(sccs, casttree);
            }
Ejemplo n.º 2
0
        public static object __BFSTestNoGeometryGeneration(List <Surface> surfaces)
        {
            var graph = ModelTopology.GenerateTopologyFromSurfaces(surfaces);

            //perform BFS on the graph and get back the tree
            var nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);

            return(nodereturn);
        }
Ejemplo n.º 3
0
        public static void AssertEachFacePairUnfoldsCorrectly(List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> > graph)
        {
            //perform BFS on the graph and get back the tree
            var    nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);
            object tree       = nodereturn;

            var casttree = tree as List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> >;
            //perform Tarjans algo and make sure that the tree is acylic before unfold
            var sccs = GraphUtilities.TarjansAlgo <EdgeLikeEntity, FaceLikeEntity> .CycleDetect(casttree, GraphUtilities.EdgeType.Tree);

            UnfoldTestUtils.IsAcylic <EdgeLikeEntity, FaceLikeEntity>(sccs, casttree);

            // iterate through each vertex in the tree
            // make sure that the parent/child is not null (depends which direction we're traversing)
            // if not null, grab the next node and the tree edge
            // pass these to check normal consistencey and align.
            // be careful about the order of passed faces

            foreach (var parent in casttree)
            {
                if (parent.GraphEdges.Count > 0)
                {
                    foreach (var edge in parent.GraphEdges)
                    {
                        var child = edge.Head;

                        double nc          = AlignPlanarFaces.CheckNormalConsistency(child.Face, parent.Face, edge.GeometryEdge);
                        var    rotatedFace = AlignPlanarFaces.MakeGeometryCoPlanarAroundEdge(nc, child.Face, parent.Face, edge.GeometryEdge);

                        UnfoldTestUtils.AssertSurfacesAreCoplanar(rotatedFace.First(), parent.Face.SurfaceEntities.First());

                        UnfoldTestUtils.AssertRotatedSurfacesDoNotShareSameCenter(rotatedFace.First(), parent.Face.SurfaceEntities.First());

                        foreach (IDisposable item in rotatedFace)
                        {
                            item.Dispose();
                        }
                    }
                }
            }
            foreach (IDisposable item in graph)
            {
                Console.WriteLine("disposing a graphnode");
                item.Dispose();
            }

            foreach (IDisposable item in casttree)
            {
                Console.WriteLine("disposing a face");
                item.Dispose();
            }
        }
            public void GenBFSTreeFromCubeFaces()
            {
                using (Solid testcube = UnfoldTestUtils.SetupCube())
                {
                    List <Face> faces = testcube.Faces.ToList();

                    var           graph     = ModelTopology.GenerateTopologyFromFaces(faces);
                    List <Object> face_objs = faces.Select(x => x as Object).ToList();

                    UnfoldTestUtils.GraphHasVertForEachFace(graph, face_objs);

                    UnfoldTestUtils.GraphHasCorrectNumberOfEdges(24, graph);

                    var    nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);
                    object tree       = nodereturn;
                    var    casttree   = tree as List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> >;

                    UnfoldTestUtils.GraphHasVertForEachFace(casttree, face_objs);
                    UnfoldTestUtils.GraphHasCorrectNumberOfTreeEdges(5, casttree);
                    UnfoldTestUtils.AssertAllFinishingTimesSet(graph);

                    var sccs = GraphUtilities.TarjansAlgo <EdgeLikeEntity, FaceLikeEntity> .CycleDetect(casttree, GraphUtilities.EdgeType.Tree);

                    UnfoldTestUtils.IsAcylic <EdgeLikeEntity, FaceLikeEntity>(sccs, casttree);

                    foreach (IDisposable item in graph)
                    {
                        Console.WriteLine("disposing a graphnode");
                        item.Dispose();
                    }


                    foreach (IDisposable item in faces)
                    {
                        Console.WriteLine("disposing a face");
                        item.Dispose();
                    }

                    foreach (IDisposable item in casttree)
                    {
                        Console.WriteLine("disposing a face");
                        item.Dispose();
                    }
                }
            }
Ejemplo n.º 5
0
        // The following methods may be removed from Import eventually
        #region explorationdebug
        // method is for debugging the BFS output visually in dynamo, very useful
        public static object __BFSTestTesselation(List <Surface> surfaces, double tolerance = -1, int maxGridLines = 512)
        {
            //handle tesselation here
            var pointtuples = Tesselation.Tessellate(surfaces, tolerance, maxGridLines);
            //convert triangles to surfaces
            List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
            {
                x[0], x[1], x[2]
            })).ToList();

            var graph = ModelTopology.GenerateTopologyFromSurfaces(trisurfaces);

            //perform BFS on the graph and get back the tree
            var nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);
            var tree       = nodereturn;

            var treegeo = ModelGraph.ProduceGeometryFromGraph <EdgeLikeEntity, FaceLikeEntity>
                              (tree as List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> >);


            return(treegeo);
        }
Ejemplo n.º 6
0
        public EquationSystem(int minRange, int maxRange, int leaves, int cycles, int adjustments, params int[][] eqs)
        {
            GraphNode cur, gate;

            System = new ModelGraph();

            RootNode root = new RootNode(new RowMaker(eqs[0].Length, minRange, maxRange, 20, cycles));

            root.AddNeighbor(new BranchNode(new Gate(cycles, eqs.Length), 3));
            System.Roots.Add(root);

            gate = root.Neighbors[0];
            System.Branches.Add((BranchNode)root.Neighbors[0]);
            cur = gate;
            cur.AddNeighbor(new BranchNode(new ProblemColumn(0, adjustments, leaves, eqs[0]), leaves + 2));
            System.Branches.Add((BranchNode)cur.Neighbors[1]);
            cur = cur.Neighbors[1];

            for (int i = 1; i < eqs.Length; i++)
            {
                for (int j = 0; j < leaves; j++)
                {
                    cur.AddNeighbor(new LeafNode(new RowAdjuster(eqs[i - 1])));
                    System.Leaves.Add((LeafNode)cur.Neighbors[1 + j]);
                }
                cur.AddNeighbor(new BranchNode(new ProblemColumn(i, adjustments, leaves, eqs[i]), leaves + 2));
                System.Branches.Add((BranchNode)cur.Neighbors[leaves + 1]);
                cur = cur.Neighbors[leaves + 1];
            }

            for (int j = 0; j < leaves; j++)
            {
                cur.AddNeighbor(new LeafNode(new RowAdjuster(eqs[eqs.Length - 1])));
                System.Leaves.Add((LeafNode)cur.Neighbors[1 + j]);
            }
            cur.AddNeighbor(gate);
        }
Ejemplo n.º 7
0
        public void TestTreeRemoval()
        {
            var graph = ModelGraph.FromDirty(Model.Query <TimeEntryModel> ());

            graph.Remove(Model.ByRemoteId <ProjectModel> (1));
        }
Ejemplo n.º 8
0
 protected override IModel CreateInstance(ModelGraph graph) => new RoslynModel(graph);
Ejemplo n.º 9
0
 private RoslynModel(ModelGraph graph)
     : base(graph)
 {
 }
Ejemplo n.º 10
0
        private async Task <DateTime?> RunInBackground(SyncMode mode, DateTime?lastRun)
        {
            var bus        = ServiceContainer.Resolve <MessageBus> ();
            var client     = ServiceContainer.Resolve <ITogglClient> ();
            var log        = ServiceContainer.Resolve <Logger> ();
            var modelStore = ServiceContainer.Resolve <IModelStore> ();

            // Resolve automatic sync mode to actual mode
            if (mode == SyncMode.Auto)
            {
                if (lastRun != null && lastRun > Time.UtcNow - TimeSpan.FromMinutes(5))
                {
                    mode = SyncMode.Push;
                }
                else
                {
                    mode = SyncMode.Full;
                }
            }

            bus.Send(new SyncStartedMessage(this, mode));

            bool      hasErrors = false;
            Exception ex        = null;

            try {
                if (mode == SyncMode.Full)
                {
                    // TODO: Purge data which isn't related to us

                    // Purge excess time entries. Do it 200 items at a time, to avoid allocating too much memory to the
                    // models to be deleted. If there are more than 200 entries, they will be removed in the next purge.
                    var q = Model.Query <TimeEntryModel> (
                        (te) => (te.IsDirty != true && te.RemoteId != null) ||
                        (te.RemoteId == null && te.DeletedAt != null))
                            .OrderBy((te) => te.StartTime, false).Skip(1000).Take(200);
                    foreach (var entry in q)
                    {
                        entry.IsPersisted = false;
                    }
                }

                if (mode.HasFlag(SyncMode.Pull))
                {
                    var changes = await client.GetChanges(lastRun)
                                  .ConfigureAwait(continueOnCapturedContext: false);

                    changes.User.IsPersisted = true;
                    foreach (var m in changes.Workspaces)
                    {
                        if (m.RemoteDeletedAt == null)
                        {
                            m.IsPersisted = true;
                            m.Users.Add(changes.User);
                        }
                    }
                    foreach (var m in changes.Tags)
                    {
                        if (m.RemoteDeletedAt == null)
                        {
                            m.IsPersisted = true;
                        }
                    }
                    foreach (var m in changes.Clients)
                    {
                        if (m.RemoteDeletedAt == null)
                        {
                            m.IsPersisted = true;
                        }
                    }
                    foreach (var m in changes.Projects)
                    {
                        if (m.RemoteDeletedAt == null)
                        {
                            m.IsPersisted = true;
                            m.Users.Add(changes.User);
                        }
                    }
                    foreach (var m in changes.Tasks)
                    {
                        if (m.RemoteDeletedAt == null)
                        {
                            m.IsPersisted = true;
                        }
                    }
                    foreach (var m in changes.TimeEntries)
                    {
                        if (m.RemoteDeletedAt == null)
                        {
                            m.IsPersisted = true;
                        }
                    }

                    if (modelStore.TryCommit())
                    {
                        // Update LastRun incase the data was persisted successfully
                        lastRun = changes.Timestamp;
                    }
                }

                if (mode.HasFlag(SyncMode.Push))
                {
                    // Construct dependency graph:
                    var graph = ModelGraph.FromDirty(Enumerable.Empty <Model> ()
                                                     .Concat(QueryDirtyModels <WorkspaceModel> ())
                                                     .Concat(QueryDirtyModels <WorkspaceUserModel> ())
                                                     .Concat(QueryDirtyModels <TagModel> ())
                                                     .Concat(QueryDirtyModels <ClientModel> ())
                                                     .Concat(QueryDirtyModels <ProjectModel> ())
                                                     .Concat(QueryDirtyModels <ProjectUserModel> ())
                                                     .Concat(QueryDirtyModels <TaskModel> ())
                                                     .Concat(QueryDirtyModels <TimeEntryModel> ().ForCurrentUser().Where((m) => m.State != TimeEntryState.New)));

                    // Start pushing the dependencies from the end nodes up
                    var tasks = new List <Task <Exception> > ();
                    while (true)
                    {
                        tasks.Clear();

                        var models = graph.EndNodes.ToList();
                        if (models.Count == 0)
                        {
                            break;
                        }

                        foreach (var model in models)
                        {
                            if (model.RemoteRejected)
                            {
                                if (model.RemoteId == null)
                                {
                                    // Creation has failed, so remove the whole branch.
                                    graph.RemoveBranch(model);
                                }
                                else
                                {
                                    graph.Remove(model);
                                }
                            }
                            else
                            {
                                tasks.Add(PushModel(model));
                            }
                        }

                        // Nothing was pushed this round
                        if (tasks.Count < 1)
                        {
                            continue;
                        }

                        await Task.WhenAll(tasks)
                        .ConfigureAwait(continueOnCapturedContext: false);

                        for (var i = 0; i < tasks.Count; i++)
                        {
                            var model = models [i];
                            var error = tasks [i].Result;

                            if (error != null)
                            {
                                if (model.RemoteId == null)
                                {
                                    // When creation fails, remove branch as there are models that depend on this
                                    // one, so there is no point in continuing with the branch.
                                    graph.RemoveBranch(model);
                                }
                                else
                                {
                                    graph.Remove(model);
                                }
                                hasErrors = true;

                                // Log error
                                var id = model.RemoteId.HasValue ? model.RemoteId.ToString() : model.Id.ToString();
                                if (error is ServerValidationException)
                                {
                                    log.Info(Tag, error, "Server rejected {0}#{1}.", model.GetType().Name, id);
                                    model.RemoteRejected = true;
                                }
                                else if (error is System.Net.Http.HttpRequestException)
                                {
                                    log.Info(Tag, error, "Failed to sync {0}#{1}.", model.GetType().Name, id);
                                }
                                else
                                {
                                    log.Warning(Tag, error, "Failed to sync {0}#{1}.", model.GetType().Name, id);
                                }
                            }
                            else
                            {
                                graph.Remove(model);
                            }
                        }
                    }

                    // Attempt to persist changes
                    modelStore.TryCommit();
                }
            } catch (Exception e) {
                if (e.IsNetworkFailure() || e is TaskCanceledException)
                {
                    log.Info(Tag, e, "Sync ({0}) failed.", mode);
                }
                else
                {
                    log.Warning(Tag, e, "Sync ({0}) failed.", mode);
                }

                hasErrors = true;
                ex        = e;
            } finally {
                bus.Send(new SyncFinishedMessage(this, mode, hasErrors, ex));
            }

            return(lastRun);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a new PolyEModel.
 /// </summary>
 /// <param name="nodes">The number of nodes on the graph.</param>
 /// <param name="kids">The number of kids each node can have at max.</param>
 /// <param name="offset">The offset from the average number of kids during generation.</param>
 /// <param name="leaf">The chance a node will be a leaf.</param>
 public PolyEModel(int nodes, int kids, int offset, int leaf)
 {
     _rand  = new Random();
     _graph = new ModelGraph(_rand, nodes, kids, offset, leaf);
     _graph.BuildSet(SpawnMaker, JuncMaker, TermMaker);
 }
Ejemplo n.º 12
0
        public static object __DebugGeoFromGraph(List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> > graph)
        {
            var output = ModelGraph.ProduceGeometryFromGraph <EdgeLikeEntity, FaceLikeEntity>(graph);

            return(output);
        }
Ejemplo n.º 13
0
 protected override IModel CreateInstance(ModelGraph graph)
 {
     return(new TestModel(graph, ItemGroups));
 }
Ejemplo n.º 14
0
 private TestModel(ModelGraph graph, ImmutableList <ImmutableList <IModelNode> > itemGroups)
     : base(graph)
 {
     ItemGroups = itemGroups;
 }