private static void Main()
        {
            // reading of channels tree from file:
            var channelsTree = CgInteraction.ReadChannelsTreeFromCg(Dir.Data("channels.cg"));

            // calculating stats:
            var floodMap   = GrdInteraction.ReadGridMapFromGrd(Dir.Data("only_territory_flood_frequency0.grd"));
            var typeUseMap = GrdInteraction.ReadGridMapFromGrd(Dir.Data("TypeUseWithNonCadastr.grd"));
            var hozValues  = new HashSet <double> {
                37, 38, 39, 43, 44, 45
            };
            var socValues = new HashSet <double> {
                58, 61, 63, 66, 171, 186, 195, 203, 207
            };
            var nonCadastrId = 8888d;
            var r            = 10;
            var stats        = StatsAggregation.GetStats(channelsTree, floodMap, typeUseMap, hozValues, socValues, nonCadastrId, r);


            /* Usage of donors-acceptors algorithm */

            // read flood series for Q=23 and t=[20, 39]:
            var floodSeries = GrdInteraction.ReadFloodSeriesFromZip(Dir.Data("flood/23.zip"), 20, 39);

            // read eco targets map
            var ecoTargetMap = GrdInteraction.ReadGridMapFromGrd(Dir.Data("frequencies/add_frequency_from_0,65_to_0,85.grd"));

            // initialization of algo:
            var donorsAcceptors = new DonorsAcceptors(
                DonorsAcceptors.RatingStrategy.TargetCount, channelsTree, ecoTargetMap, floodSeries);

            // on each iteration call method Run with CofinanceInfo:
            var cofinanceInfo = new CofinanceInfo(0, null);
            var projectPlan   = donorsAcceptors.Run(cofinanceInfo);
        }
        private static void Run(Options options)
        {
            var bitmap      = new Bitmap(options.ChannelsImagePath);
            var wasEnqueued = new HashSet <(int, int)>();
            var components  = new List <Channel>();
            var id          = 0;

            for (var x = 0; x < bitmap.Width; x++)
            {
                for (var y = 0; y < bitmap.Height; y++)
                {
                    var color = bitmap.GetPixel(x, y);
                    if (color == ORANGE && !wasEnqueued.Contains((x, y)))
                    {
                        components.Add(Parse(ref id, (x, y), bitmap, wasEnqueued));
                    }
                }
            }

            var contrastColors = new[]
            {
                Color.Red,
                Color.LightGreen,
                Color.Black,
                Color.Violet,
                Color.Blue,
                Color.Cyan,
                Color.Magenta
            };

            var debugBitmap = Drawing.DrawBitmap(bitmap.Width, bitmap.Height, g =>
            {
                for (var i = 0; i < components.Count; i++)
                {
                    DrawComponent(components[i], g, contrastColors[i]);
                }
            });

            debugBitmap.Save(options.DebugImgOutPath);

            var graph = new ChannelsGraph(components);

            ImproveConnections(graph, bitmap);

            CgInteraction.WriteChannelsGraphToCg(options.CGOutPath, graph);

            Console.WriteLine($"Found {components.Count} components");
        }
 static void Main(string[] args)
 {
     Parser.Default.ParseArguments <Options>(args).WithParsed(o =>
     {
         var channels    = CgInteraction.ReadChannelsTreeFromCg(o.ChannelsGraphFile);
         var floodSeries = FloodseriesZip.Read(o.FloodSeriesFile, o.StartDay, o.EndDay);
         Dir.RequireClearDirectory(o.OutputDir);
         foreach (var day in floodSeries.Days)
         {
             var bitmap = DrawDirectionsBitmap(channels, day.VxMap, day.VyMap);
             bitmap.Save($"{o.OutputDir}/{day.T}.png");
         }
     });
     System.Console.WriteLine("Press any key to continue...");
     System.Console.ReadKey();
 }
Exemple #4
0
        static void Main(string[] args)
        {
            var channels = CgInteraction.ReadChannelsTreeFromCg(Dir.Data("channels_all.cg"));

            RestoreHoles(channels);
            RestoreChildren(channels);
            CheckChannels(channels);
            CgInteraction.WriteChannelsTreeToCg(Dir.Data("channels.cg"), channels);
            BinarizeChannels(channels);
            var bitmap = Drawing.DrawBitmap(944, 944, g =>
            {
                Drawing.DrawChannels(g, channels.GetAllChannels(), new SolidBrush(Color.Black), true);
            });

            bitmap.Save(Dir.Data("restoration_debug.png"));
            Console.WriteLine(channels.GetAllChannels().Count());
            CgInteraction.WriteChannelsTreeToCg(Dir.Data("channels_binarized.cg"), channels);
        }
        private static void Run(Options options)
        {
            var relief      = Grd.Read(options.ReliefFile);
            var targetMap   = Grd.Read(options.TargetMapFile);
            var floodSeries = FloodseriesZip.Read(options.FloodSeriesFile, options.StartDay, options.EndDay);
            var channels    = CgInteraction.ReadChannelsTreeFromCg(options.ChannelsGraphFile);

            var drawingsDir = $"{options.OutputDir}/vis";
            var mapsDir     = $"{options.OutputDir}/maps";

            Dir.RequireClearDirectory(drawingsDir);
            Dir.RequireClearDirectory(mapsDir);

            var floodMap = DrawFloodMapWithTargets(floodSeries, targetMap, options.TargetValue);

            floodMap.Save($"{options.OutputDir}/floodmap.png");

            var strategies = new[]
Exemple #6
0
        private static void Run(Options options)
        {
            var graph = CgInteraction.ReadChannelsTreeFromCg(options.CgPath);

            var contrastColors = new[]
            {
                Color.DeepPink,
                Color.LightGreen,
                Color.Black,
                Color.Violet,
                Color.Blue,
                Color.Cyan,
                Color.Magenta,
                Color.Aqua,
                Color.Azure,
                Color.Coral,
                Color.DarkSalmon,
                Color.Firebrick,
                Color.Green,
                Color.Red,
                Color.LightGreen,
                Color.Black,
                Color.Violet,
                Color.DeepSkyBlue,
                Color.DodgerBlue
            };

            Console.WriteLine($"Components count: {graph.Root.Connecions.Count}");

            var bitmap = Drawing.DrawBitmap(944, 944, g =>
            {
                foreach ((var color, var baseChannel) in graph.Root.Connecions.Zip(
                             contrastColors, (color, channel) => (channel, color)))
                {
                    var channels = new List <Channel>();
                    graph.VisitChannelsDepthFromTop(baseChannel, (channel, depth) =>
                    {
                        channels.Add(channel);
                    });
                    Drawing.DrawChannels(g, channels, new SolidBrush(color));
                }
            });
Exemple #7
0
        private static void Run(Options options)
        {
            var graph = CgInteraction.ReadChannelsGraphFromCg(options.GraphPath);
            var flood = FloodseriesZip.Read(options.FloodPath, 20, 20);

            var hMap  = flood.Days[0].HMap;
            var vxMap = flood.Days[0].VxMap;
            var vyMap = flood.Days[0].VyMap;

            var channelById = new Dictionary <long, Channel>();
            var channels    = new List <Channel>();

            graph.BFS(channel =>
            {
                var direction      = GetChannelDirection(channel, flood.Days[0]);
                channel.Connecions = channel.Connecions.Where(child => {
                    var directionBetween = GetDirectionBetweenChannels(channel, child);
                    return(IsSodirected(direction, directionBetween));
                }).ToList();
                channelById[channel.Id] = channel;
                channels.Add(channel);
            });

            var interestingId = new List <long>()
            {
                74, 77, 87, 86, 90, 91, 109, 108, 151, 152, 103, 105, 104, 131, 130, 163, 164
            };

            var reportCsv = "id,q_entrance,q_exit,loss,is_source";

            foreach (var channel in channels)
            {
                var n = 3;

                var vxEntrance = 0d;
                var vyEntrance = 0d;
                var hEntrance  = 0d;

                for (var i = 0; i < n && i < channel.Points.Count; i++)
                {
                    var p = channel.Points[i];
                    vxEntrance += vxMap[p.X, p.Y - 1] / n;
                    vyEntrance += vyMap[p.X, p.Y - 1] / n;
                    hEntrance  += hMap[p.X, p.Y - 1] / n;
                }

                var qEntrance = Length(new Vec(vxEntrance, vyEntrance)) * 25 * hEntrance;

                var vxExit = 0d;
                var vyExit = 0d;
                var hExit  = 0d;

                for (var i = 0; i < n && i < channel.Points.Count; i++)
                {
                    var p = channel.Points[channel.Points.Count - i - 1];
                    vxExit += vxMap[p.X, p.Y - 1] / n;
                    vyExit += vyMap[p.X, p.Y - 1] / n;
                    hExit  += hMap[p.X, p.Y - 1] / n;
                }

                var qExit = Length(new Vec(vxExit, vyExit)) * 25 * hExit;

                reportCsv += $"\n{channel.Id},{qEntrance},{qExit},{qEntrance - qExit},{(channel.IsEntrance ? 1 : 0)}";
            }

            File.WriteAllText(options.ReportOutPath, reportCsv);
            CgInteraction.WriteChannelsGraphToCg(options.GraphOutPath, graph);
        }