/// <summary> Сгенерировать отладочный вариант </summary> protected override TaskVariantDto GetDebugVariant() { var debugGraph1 = UndirectedGraph.CreateEmpty(7); debugGraph1.AddEdge(new UndirectedEdge(debugGraph1.Vertices[0], debugGraph1.Vertices[1])); debugGraph1.AddEdge(new UndirectedEdge(debugGraph1.Vertices[0], debugGraph1.Vertices[6])); debugGraph1.AddEdge(new UndirectedEdge(debugGraph1.Vertices[0], debugGraph1.Vertices[2])); var debugGraph2 = UndirectedGraph.CreateEmpty(7); debugGraph2.AddEdge(new UndirectedEdge(debugGraph2.Vertices[0], debugGraph2.Vertices[1])); debugGraph2.AddEdge(new UndirectedEdge(debugGraph2.Vertices[0], debugGraph2.Vertices[6])); debugGraph2.AddEdge(new UndirectedEdge(debugGraph2.Vertices[0], debugGraph2.Vertices[2])); var serializedVariant = VariantSerializer.Serialize(new IGraph[] { debugGraph1, debugGraph2 }); return(new TaskVariantDto { Data = serializedVariant, GeneratorVersion = "1.0", Number = "Debug", Version = 1 }); }
private static bool Unique(IGraph g, IEnumerable <IGraph> c) { var unique = true; var gCopy = UndirectedGraph.CreateEmpty(g.VerticesCount); for (var i = 0; i < g.VerticesCount; i++) { for (var j = i + 1; j < g.VerticesCount; j++) { if (g[g.Vertices[i], g.Vertices[j]] != null) { gCopy.AddEdge(new UndirectedEdge(gCopy.Vertices[i], gCopy.Vertices[j])); } } } var graphs = new ObservableCollection <IGraph>(); var n = F(gCopy.VerticesCount); for (var i = 0; i < n; i++) { graphs.Add(CombUndGraph(gCopy, i)); } graphs.ForEach(g1 => c.ForEach(g2 => unique &= !g1.Equals(g2) ) ); return(unique); }
public void CreateEmptyTest() { var graph = UndirectedGraph.CreateEmpty(5); Assert.AreEqual(graph.VerticesCount, 5); Assert.AreEqual(graph.EdgesCount, 0); }
/// <summary> Задание загружено </summary> /// <param name="e"></param> protected override void OnTaskLoadingComlete(VariantDownloadedEventArgs e) { // Мы вызваны из другого потока. Поэтому работаем с UI-элементами через Dispatcher. Dispatcher.BeginInvoke(() => { var data = VariantSerializer.Deserialize(e.Data); GivenGraph = data[0]; CurrentGraph = UndirectedGraph.CreateEmpty(GivenGraph.VerticesCount); }); //var number = e.Number; -- м.б. тоже где-то показать надо //var version = e.Version; }
private void InitToolBarCommands() { #region Первый этап #region Добавление рёбер var phase1AddEdgeCommand = new ToolBarToggleCommand( () => { IsMouseVerticesMovingEnabled = false; IsEgesAddingEnabled = true; _state = State.EdgesAdding; }, () => { IsMouseVerticesMovingEnabled = true; IsEgesAddingEnabled = false; _state = State.Nothing; }, () => _state == State.Nothing, () => true ) { Image = new BitmapImage(GetImageUri("Arrow.png")), Description = Strings.Strings_RU.buttonEdges }; #endregion #region Завершить этап var allSubgraphs = new ObservableCollection <IGraph>(); var phase1Command = new ToolBarInstantCommand( () => { var solve = true; var gp = new GraphPrinter(); UserActionsManager.RegisterInfo(Strings.Strings_RU.stage1Check + gp.GraphToString(CurrentGraph)); CurrentGraph.Vertices.ForEach(v1 => CurrentGraph.Vertices.ForEach(v2 => { solve = solve && (v1.Equals(v2) || (CurrentGraph[v1, v2] == null ^ GivenGraph[ GivenGraph.Vertices.Single(v1.Equals), GivenGraph.Vertices.Single(v2.Equals)] == null )); } )); if (solve) { UserActionsManager.RegisterInfo(Strings.Strings_RU.stage1Done); GivenGraph = CurrentGraph; CurrentGraph = new UndirectedGraph(); Phase1ToolBarVisibility = Visibility.Collapsed; Phase2ToolBarVisibility = Visibility.Visible; L1 = Strings.Strings_RU.subgraph; FindAllSubgraphs(GivenGraph, 0, GivenGraph.Vertices.ToList(), allSubgraphs); new SimpleDialog("Справка", Strings.Strings_RU.stage2Help).Show(); } else { UserActionsManager.RegisterMistake(Strings.Strings_RU.stage1Mistake1, 10); } }, () => _state == State.Nothing ) { Image = new BitmapImage(GetImageUri("Check.png")), Description = Strings.Strings_RU.stage1DoneButtonDisc }; #endregion #region Справка var phase1HelpCommand = new ToolBarInstantCommand( () => { new SimpleDialog("Справка", Strings.Strings_RU.stage1Help).Show(); }, () => _state == State.Nothing ) { Description = Strings.Strings_RU.buttonHelp, Image = new BitmapImage(GetImageUri("Info.png")) }; #endregion #region Молния var thunderbolt1 = new ToolBarInstantCommand( () => { UserActionsManager.RegisterInfo(Strings.Strings_RU.stage1ThunderCall); CurrentGraph.Vertices.ForEach(v1 => CurrentGraph.Vertices.ForEach(v2 => { if (!v1.Equals(v2) && CurrentGraph[v1, v2] == null && GivenGraph[ GivenGraph.Vertices.Single(v1.Equals), GivenGraph.Vertices.Single(v2.Equals)] == null) { CurrentGraph.AddEdge(new UndirectedEdge((Vertex)v1, (Vertex)v2)); } if (!v1.Equals(v2) && CurrentGraph[v1, v2] != null && GivenGraph[ GivenGraph.Vertices.Single(v1.Equals), GivenGraph.Vertices.Single(v2.Equals)] != null) { CurrentGraph.RemoveEdge(CurrentGraph[v1, v2]); } } )); }, () => _state == State.Nothing ) { Description = "Молния", Image = new BitmapImage(GetImageUri("thunder.png")) }; #endregion #endregion #region Второй этап #region Добавление вершин var vertexDialogCommand = new ToolBarInstantCommand( () => { var dialog = new VertexDialog((UndirectedGraph)CurrentGraph, GivenGraph.Vertices); dialog.Show(); dialog.Closed += (sender, args) => { var buf = CurrentGraph; CurrentGraph = null; CurrentGraph = buf; }; }, () => _state == State.Nothing) { Image = new BitmapImage(GetImageUri("Vertexes.png")), Description = Strings.Strings_RU.buttonVertexDialog }; #endregion #region Добавление рёбер var phase2AddEdgeCommand = new ToolBarToggleCommand( () => { IsMouseVerticesMovingEnabled = false; IsEgesAddingEnabled = true; _state = State.EdgesAdding; }, () => { IsMouseVerticesMovingEnabled = true; IsEgesAddingEnabled = false; _state = State.Nothing; }, () => _state == State.Nothing, () => true ) { Image = new BitmapImage(GetImageUri("Arrow.png")), Description = Strings.Strings_RU.buttonEdges }; #endregion #region Добавление подграфов var subgraphCommand = new ToolBarInstantCommand( () => { var subgraph = true; var unique = Unique((UndirectedGraph)CurrentGraph, GraphLib.Lib); var gp = new GraphPrinter(); UserActionsManager.RegisterInfo(Strings.Strings_RU.stage2Check + gp.GraphToString(CurrentGraph)); CurrentGraph.Vertices.ForEach(v1 => { CurrentGraph.Vertices.ForEach(v2 => { subgraph &= v1.Equals(v2) || (CurrentGraph[v1, v2] == null ^ GivenGraph[ GivenGraph.Vertices.Single(v1.Equals), GivenGraph.Vertices.Single(v2.Equals)] != null); } ); } ); if (CurrentGraph.VerticesCount == 0) { return; } if (!subgraph) { UserActionsManager.RegisterMistake(Strings.Strings_RU.stage2Mistake1, 10); return; } if (!unique) { UserActionsManager.RegisterMistake(Strings.Strings_RU.stage2Mistake2, 10); return; } var newGraph = UndirectedGraph.CreateEmpty(CurrentGraph.VerticesCount); for (var i = 0; i < CurrentGraph.VerticesCount; i++) { for (var j = i + 1; j < CurrentGraph.VerticesCount; j++) { if (CurrentGraph[CurrentGraph.Vertices[i], CurrentGraph.Vertices[j]] != null) { newGraph.AddEdge(new UndirectedEdge(newGraph.Vertices[i], newGraph.Vertices[j])); } } } UserActionsManager.RegisterInfo(Strings.Strings_RU.stage2Subgraph); GraphLib.Lib.Add(newGraph); }, () => _state == State.Nothing ) { Image = new BitmapImage(GetImageUri("Collection.png")), Description = Strings.Strings_RU.buttonCheckSubgraph }; #endregion #region Справка var phase2HelpCommand = new ToolBarInstantCommand( () => { new SimpleDialog("Справка", Strings.Strings_RU.stage2Help).Show(); }, () => _state == State.Nothing ) { Description = Strings.Strings_RU.buttonHelp, Image = new BitmapImage(GetImageUri("Info.png")) }; #endregion #region Молния var thunderbolt2 = new ToolBarInstantCommand( () => { UserActionsManager.RegisterInfo(Strings.Strings_RU.stage2ThunderCall); allSubgraphs.ForEach(s => { if (Unique(s, GraphLib.Lib)) { GraphLib.Lib.Add(s); } }); var g = UndirectedGraph.CreateEmpty(GivenGraph.VerticesCount); for (var i = 0; i < g.VerticesCount; i++) { for (var j = i + 1; j < g.VerticesCount; j++) { if (GivenGraph[GivenGraph.Vertices[i], GivenGraph.Vertices[j]] != null) { g.AddEdge(new UndirectedEdge(g.Vertices[i], g.Vertices[j])); } } } GraphLib.Lib.Add(g); }, () => _state == State.Nothing ) { Description = "Молния", Image = new BitmapImage(GetImageUri("thunder.png")) }; #endregion #region Завершить этап var phase2Command = new ToolBarInstantCommand( () => { if (GraphLib.Lib.Count > allSubgraphs.Count) { UserActionsManager.RegisterInfo(Strings.Strings_RU.stage2Done); UserActionsManager.ReportThatTaskFinished(); } else { UserActionsManager.RegisterMistake(Strings.Strings_RU.stage2Mistake3, 10); } }, () => _state == State.Nothing ) { Image = new BitmapImage(GetImageUri("Check.png")), Description = Strings.Strings_RU.stage2DoneButtonDisc }; #endregion #endregion Phase1ToolBarCommands = new ObservableCollection <ToolBarCommandBase> { phase1AddEdgeCommand, phase1Command, phase1HelpCommand #if DEBUG , thunderbolt1 #endif }; Phase2ToolBarCommands = new ObservableCollection <ToolBarCommandBase> { vertexDialogCommand, phase2AddEdgeCommand, subgraphCommand, phase2Command, phase2HelpCommand #if DEBUG , thunderbolt2 #endif }; }