Пример #1
0
        // ===== Positivize =====

        public static (Lst <Polynomize.PolyODE> posOdes, Lst <Polynomize.Equation> posEqs, Dictionary <Symbol, SpeciesFlow> dict, Lst <Subst> substs) PositivizeODEs(Lst <Polynomize.PolyODE> odes, Lst <Polynomize.Equation> eqs, Style style)
        {
            // We could split all variables to be sure, but we try to be clever:
            // Split only those variables that have non-Hungarian monomials.
            // However, substitution of the split variables may introduce new non-Hungarian monomials, so we need to iterate until closure.
            // Moreover, some non-split variables may get initialized to negative values (consider #->x{{log(x)}} with x0=0.9, whose polynomization is Hungarian but log(x0)<0),
            // so they must be split too even if their monomials are Hungarian
            Lst <Polynomize.PolyODE>  resOdes = odes;
            Lst <Polynomize.Equation> resEqs  = eqs;
            Lst <Subst> accumulatedSubsts     = Subst.nil;

            while (true)
            {
                Lst <Subst> newSubsts = NecessarySubsts(resOdes, resEqs, style); // it will ignore already split odes
                //Gui.Log("PolyODEs:" + Environment.NewLine + Polynomize.Format(unsplit.Append(split), style));
                //Gui.Log("NecessarySubsts:" + Environment.NewLine + Format(substs, style));
                if (newSubsts is Nil <Subst> ) // we converged
                {
                    Lst <SpeciesFlow> unsplitVars = UnsplitVars(odes, accumulatedSubsts);
                    (Lst <Polynomize.PolyODE> renOdes, Lst <Polynomize.Equation> renEqs, Dictionary <Symbol, SpeciesFlow> dict) = Rename(unsplitVars, resOdes, resEqs, style);
                    return(renOdes, renEqs, dict, accumulatedSubsts);
                }
                accumulatedSubsts = newSubsts.Append(accumulatedSubsts);
                resOdes           = PositivizeODEs(odes, accumulatedSubsts, style);
                resEqs            = Substitute(eqs, accumulatedSubsts, style);
            }
        }
Пример #2
0
            public void TryAdd(FileInfo file)
            {
                IEnumerable <Task> CreateTasks(FileInfo f)
                {
                    if (f.Directory != File.Directory || f == File)
                    {
                        return(Lst <Task> .Empty);
                    }

                    var m = NamePattern.Match(f.Name);

                    if (!m.Success || m.Groups[1].Value != Key)
                    {
                        return(Lst <Task> .Empty);
                    }

                    var key = m.Groups[2].Value;

                    if (key.ToLower().StartsWith("morphs"))
                    {
                        Lst <string> shapes;

                        using (var mesh = ResourceLoader.Load <ArrayMesh>(f.Path))
                        {
                            shapes = mesh.GetBlendShapeNames().Freeze();
                        }

                        string NormalizeName(string name)
                        {
                            const string prefix = "morphs_";

                            if (name.ToLower().StartsWith(prefix))
                            {
                                return(name.Substring(prefix.Length));
                            }

                            return(name);
                        }

                        return
                            (from shape in shapes
                             from surface in Surfaces
                             select new BlendShapeTask(NormalizeName(shape), f, surface, shape, this));
                    }

                    return(Surfaces.Map(s => new MorphedMeshTask(key, f, s, this)).Freeze());
                }

                var newTasks = CreateTasks(file);

                _tasks = _tasks.Append(newTasks).Freeze();
            }
Пример #3
0
        public static void LstAppend(int[] xs, int elem)
        {
            var fl         = new Lst <int>(xs);
            var origLength = fl.Count;
            var fl2        = fl.Append(elem);

            var list = new List <int>(xs ?? new int[0])
            {
                elem
            };

            Assert.Equal(list, fl2);
            Assert.Equal(origLength, fl.Count);
            Assert.Equal(origLength + 1, fl2.Count);
        }
Пример #4
0
 public Lst <A> Append(Lst <A> x, Lst <A> y) =>
 x.Append(y);