public static OptimizerService.SimpleHypergrid EncodeHypergrid(Hypergrid hypergrid)
        {
            OptimizerService.SimpleHypergrid instance = new OptimizerService.SimpleHypergrid();

            instance.GuestSubgrids.AddRange(hypergrid.Subgrids.SelectMany(subgridSet => subgridSet.Value.Select(subgrid => EncodeJoinedSubgrid(subgrid))));

            instance.Dimensions.AddRange(hypergrid.Dimensions.Select(dimension => EncodeDimension(dimension)));

            instance.Name = hypergrid.Name;

            return(instance);
        }
        public static Hypergrid DecodeHypergrid(OptimizerService.SimpleHypergrid hypergrid)
        {
            IDimension[] dimensions = hypergrid.Dimensions.Select(dimension => DecodeDimension(dimension)).ToArray();

            var instance = new Hypergrid(name: hypergrid.Name, dimensions: dimensions);

            foreach (var subgrid in hypergrid.GuestSubgrids)
            {
                instance.Join(DecodeHypergrid(subgrid.Subgrid), DecodeDimension(subgrid.ExternalPivotDimension));
            }

            return(instance);
        }