Esempio n. 1
0
    void use_erdosrenyi_graph_generator(const vle::devs::InitEventList& events)
    {
        vle::translator::graph_generator::parameter param{
            std::bind(&Builder::graph_generator_make_model,
                      this,
                      std::placeholders::_1,
                      std::placeholders::_2,
                      std::placeholders::_3),
            graph_generator_connectivity(),
            directed
        };

        vle::translator::graph_generator gg(param);

        if (events.exist("fraction"))
            gg.make_erdos_renyi(*this,
                                generator,
                                model_number,
                                events.getDouble("fraction"),
                                events.getBoolean("allow-self-loops"));
        else
            gg.make_erdos_renyi(*this,
                                generator,
                                model_number,
                                events.getInt("edges_number"),
                                events.getBoolean("allow-self-loops"));
    }
Esempio n. 2
0
    void use_1d_regular_graph_generator(const vle::devs::InitEventList& events)
    {
        vle::translator::regular_graph_generator::parameter param{
            std::bind(&Builder::regular_graph_generator_make_model,
                      this,
                      std::placeholders::_1,
                      std::placeholders::_2,
                      std::placeholders::_3),
            regular_graph_generator_connectivity()
        };

        vle::translator::regular_graph_generator rgg(param);

        const auto& v = events.getSet("mask").value();
        std::vector<std::string> mask;

        std::transform(v.begin(),
                       v.end(),
                       std::back_inserter(mask),
                       [](const auto& v) { return v->toString().value(); });

        rgg.make_1d(*this,
                    events.getInt("lenght"),
                    events.getBoolean("graph-wrap"),
                    mask,
                    events.getInt("x-mask"));
    }
    TimeSlicingMethod(DifferentialEquation& eq,
            const vd::InitEventList& events) :
            DifferentialEquationImpl(eq, events), devs_state(INIT),
            devs_options(), devs_guards(), devs_internal(),
            int_method(*this, events)
    {
        if (events.exist("output_period")) {
            const value::Value& v = *(events.get("output_period"));
            devs_options.output_period = 0;
            if (v.isInteger()) {
                devs_options.output_period = v.toInteger().value();
            }
            if (devs_options.output_period < 1) {
                throw utils::ModellingError(vle::utils::format(
                        "[%s] Parameter 'output_period' should be an int > 0",
                        getModelName().c_str()));
            }
        }
        if (events.exist("time_step")) {
            devs_options.dt = events.getDouble("time_step");
            if (devs_options.dt <= 0) {
                throw utils::ModellingError(vle::utils::format(
                        "[%s] Parameter 'time_step' should be > 0",
                        getModelName().c_str()));
            }
        }

    }
Esempio n. 4
0
    Generator(const vd::DynamicsInit& init, const vd::InitEventList& events)
      : vd::Dynamics(init, events)
    {
        vg::ConnectionList my_list;

        // m_duration = vv::toDouble(events.get("duration"));
        m_duration = 0.1;
        if (events.end() != events.find("source_init_level")) {
            m_val = vv::toDouble(events.get("source_init_level"));
        } else {
            m_val = 1;
            Trace(6,
                  "Warning : Model %s got no init"
                  " output level (source_init_level) : assuming 1\n",
                  getModelName().c_str());
        }

        if (events.end() != events.find("source_trend")) {
            m_trend = vv::toDouble(events.get("source_trend"));
            if (events.end() != events.find("source_quantum")) {
                m_quantum = vv::toDouble(events.get("source_quantum"));
            } else {
                m_quantum = 0.01;
                Trace(6,
                      "Warning : Model %s got no output"
                      " quantum (source_quantum) : assuming 0.01\n",
                      getModelName().c_str());
            }
        } else {
            m_trend = 0;

            Trace(6,
                  "%s got no output trend (source_trend)"
                  " : assuming 0\n",
                  getModelName().c_str());

            // no trend => quantum is useless but..
            m_quantum = 0.01;
        }

        if (0 == m_quantum) {
            throw vu::ModellingError("Model %s has null output quantum.",
                                     getModelName().c_str());
        }

        m_has_output_port = false;
        my_list = getModel().getOutputPortList();

        if (my_list.size() > 0) {
            m_output_port_label = (my_list.begin())->first;
            m_has_output_port = true;
        }

        if (my_list.size() > 1) {
            Trace(6,
                  "Warning: multiple output ports."
                  " Will use only port %s\n",
                  m_output_port_label.c_str());
        }
    }
Esempio n. 5
0
        Rm(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
               DifferentialEquation(model,events)
        {
            gamma = events.getDouble("gamma"); //= 0.2
            nu  = events.getDouble("nu");// = 0.0

            R.init(this, "R", events);
            S.init(this, "S", events);
            I.init(this, "I", events);
        }
Esempio n. 6
0
        Rm(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            gamma = events.getDouble("gamma"); //= 0.2
            nu  = events.getDouble("nu");// = 0.0

            R = createVar("R");
            S = createExt("S");
            I = createExt("I");
        }
Esempio n. 7
0
        LotkaVolterraY(const vle::devs::DynamicsInit& model,
                       const vle::devs::InitEventList& events) :
            DifferentialEquation(model,events)
        {
            gamma = (events.exist("gamma"))
                ? events.getDouble("gamma") : 0.5;
            delta = (events.exist("delta"))
                ? events.getDouble("delta") : 0.5;

            Y.init(this, "Y", events);
            X.init(this, "X", events);
        }
Esempio n. 8
0
        LotkaVolterraX(const vle::devs::DynamicsInit& model,
                       const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {

            alpha = (events.exist("alpha"))
                ? events.getDouble("alpha") : 0.5;
            beta = (events.exist("beta"))
                ? events.getDouble("beta") : 0.5;

            X = createVar("X");
            Y = createExt("Y");
        }
Esempio n. 9
0
        LotkaVolterraY(const vle::devs::DynamicsInit& model,
                       const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            gamma = (events.exist("gamma"))
                ? events.getDouble("gamma") : 0.5;
            delta = (events.exist("delta"))
                ? events.getDouble("delta") : 0.5;


            Y = createVar("Y");
            X = createExt("X");
        }
Esempio n. 10
0
File: Sm.cpp Progetto: GG31/packages
        Sm(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            beta = events.getDouble("beta");// = 0.9
            nu  = events.getDouble("nu");// = 0.0

            S = createVar("S");                  
            E = createExt("E");
            I = createExt("I");
            R = createExt("R");

        }
Esempio n. 11
0
    ExBohachevsky(const vd::DynamicsInit& init, const vd::InitEventList& events) :
        vd::Dynamics(init,events)
    {
        x1 = events.getDouble("x1");
        x2 = events.getDouble("x2");

        my = pow(x1,2) + 2 * pow(x2,2) - 0.3 * cos(3 * M_PI * x1)
                - 0.4 * cos(4 * M_PI * x2) + 0.7;

        mrand.seed(events.getInt("seed"));
        double noise = mrand.normal(0,0.1);
        my_noise = my + noise;
    }
Esempio n. 12
0
    void use_defined_graph_generator(const vle::devs::InitEventList& events)
    {
        vle::utils::Array<bool> userdefined(model_number, model_number);

        {
            const auto& v = events.getTuple("user-defined");
            if (v.size() != vle::utils::numeric_cast<std::size_t>(
                              model_number * model_number))
                throw vle::utils::ModellingError(
                  "User defined model size error");

            int pos = 0;
            for (int i = 0; i != model_number; ++i)
                for (int j = 0; j != model_number; ++j, ++pos)
                    userdefined(i, j) = (v.get(pos) != 0.0);
        }

        vle::translator::graph_generator::parameter param{
            std::bind(&Builder::graph_generator_make_model,
                      this,
                      std::placeholders::_1,
                      std::placeholders::_2,
                      std::placeholders::_3),
            graph_generator_connectivity(),
            directed
        };

        vle::translator::graph_generator gg(param);

        gg.make_graph(*this, model_number, userdefined);
    }
Esempio n. 13
0
File: M.cpp Progetto: GG31/ibm
    M(
       const vd::DynamicsInit& init,
       const vd::InitEventList& events)
    : ve::DifferentialEquation(init, events)
    {
        C3 = createVar("C3");
        C1 = createVar("C1");
        DSAT = createVar("DSAT");
        C2 = createVar("C2");


        if (events.exist("p1"))
            p1 = events.getDouble("p1");
        else
            throw vle::utils::ModellingError("Parameter p1 not found");

    }
Esempio n. 14
0
        Seir(const vle::devs::DynamicsInit& model,
             const vle::devs::InitEventList& events) :
                 DifferentialEquation(model,events)
        {

            beta = events.getDouble("beta");// = 0.9
            gamma = events.getDouble("gamma"); //= 0.2
            sigma = events.getDouble("sigma"); // = 0.5
            nu  = events.getDouble("nu");// = 0.0

            S.init(this, "S", events);
            E.init(this, "E", events);
            I.init(this, "I", events);
            R.init(this, "R", events);

            n = S()+E()+I()+R();

        }
Esempio n. 15
0
 XRay::XRay(const vd::DynamicsInit& init, const vd::InitEventList& events)
     : vd::Dynamics(init, events)
 {
   mProbabilityRightSR = vv::toDouble(events.get("probabilityRightSR"));
   mProbabilityRightI = vv::toDouble(events.get("probabilityRightI"));
   mObservationTimeStep =  vv::toDouble(events.get("timeStep"));
   if (events.exist("R_INIT") and 
       (vv::toBoolean(events.get("R_INIT")))) {
       mNbModel =vv::toInteger(events.get("graphInfo_number"));
       mPrefix =vv::toString(events.get("graphInfo_prefix"));
   } else {
       mNbModel = events.getMap("graphInfo").getInt("number");
       mPrefix = events.getMap("graphInfo").getString("prefix");
   }
   mSampleSize = /*boost::lexical_cast<int>*/ (vv::toDouble(events.get("echProp")) * mNbModel);
   //std::cout<<"smplesize= "<<mSampleSize<<"\n";
   mPrevalence=0.; mIncidence=0.;
     }
Esempio n. 16
0
 LogEx(const vle::devs::DynamicsInit& init, const vle::devs::InitEventList& events)
     : DiscreteTimeDyn(init, events)
 {
     x.init(this, "x",events);
     y.init(this, "y",events);
     y_noise.init(this, "y_noise",events);
     y.init_value(x());
     y_noise.init_value(x());
     mrand.seed(events.getInt("seed"));
 }
Esempio n. 17
0
File: Im.cpp Progetto: GG31/packages
        Im(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
            ved::DifferentialEquation(model,events)
        {
            gamma = events.getDouble("gamma"); //= 0.2
            sigma = events.getDouble("sigma"); // = 0.5

            I = createVar("I");
            E = createExt("E");
        }
Esempio n. 18
0
        Im(const vle::devs::DynamicsInit& model,
           const vle::devs::InitEventList& events) :
               DifferentialEquation(model,events)
        {
            gamma = events.getDouble("gamma"); //= 0.2
            sigma = events.getDouble("sigma"); // = 0.5

            I.init(this, "I", events);
            E.init(this, "E", events);
        }
Esempio n. 19
0
    void use_regular_graph_generator(const vle::devs::InitEventList& events)
    {
        int dimension = events.getInt("graph-dimension");

        if (dimension == 1)
            use_1d_regular_graph_generator(events);
        else if (dimension == 2)
            use_2d_regular_graph_generator(events);
        else
            throw vle::utils::ModellingError(
              "Undefined regular graph with %d dimension", dimension);
    }
Esempio n. 20
0
File: Y.cpp Progetto: Chabrier/ibm2
    Y(
       const vd::DynamicsInit& init,
       const vd::InitEventList& events)
    : ve::DifferentialEquation(init, events)
    {
        X = createVar("X");
        maturing = createVar("maturing");
        masse = createVar("masse");


        if (events.exist("KS"))
            KS = events.getDouble("KS");
        else
            throw vle::utils::ModellingError("Parameter KS not found");

        if (events.exist("KG"))
            KG = events.getDouble("KG");
        else
            throw vle::utils::ModellingError("Parameter KG not found");

    }
Esempio n. 21
0
    void use_sortederdesrenyi_graph_generator(
      const vle::devs::InitEventList& events)
    {
        vle::translator::graph_generator::parameter param{
            std::bind(&Builder::graph_generator_make_model,
                      this,
                      std::placeholders::_1,
                      std::placeholders::_2,
                      std::placeholders::_3),
            graph_generator_connectivity(),
            directed
        };

        vle::translator::graph_generator gg(param);

        gg.make_sorted_erdos_renyi(*this,
                                   generator,
                                   model_number,
                                   events.getDouble("probability"),
                                   events.getBoolean("allow-self-loops"));
    }
Esempio n. 22
0
    void use_graph_generator(const vle::devs::InitEventList& events)
    {
        model_number = events.getInt("model-number");
        std::string generator_name = events.getString("graph-generator");

        if (events.exist("graph-seed"))
            generator.seed(events.getInt("graph-seed"));

        if (generator_name == "defined")
            use_defined_graph_generator(events);
        else if (generator_name == "small-world")
            use_smallworld_graph_generator(events);
        else if (generator_name == "scale-free")
            use_scalefree_graph_generator(events);
        else if (generator_name == "sorted-erdos-renyi")
            use_sortederdesrenyi_graph_generator(events);
        else if (generator_name == "erdos_renyi")
            use_erdosrenyi_graph_generator(events);
        else
            throw vle::utils::ModellingError("Unknown graph gererator: %s",
                                             generator_name.c_str());
    }
Esempio n. 23
0
    Smartgardener(
        const vd::DynamicsInit& init,
        const vd::InitEventList& evts)
        : vmd::Agent(init, evts),
          plantlouse_population(0),
          ladybird_population(0),
          treatment_effect_on_plantlouse(0),
          treatment_effect_on_ladybird(0),
          plantlouse_max_population(1000),
          ladybird_min_population(-1000)
    {
        treatment_effect_on_plantlouse =
                evts.getDouble("treatment_effect_on_plantlouse");
        treatment_effect_on_ladybird =
                evts.getDouble("treatment_effect_on_ladybird");
        plantlouse_max_population =
                evts.getDouble("plantlouse_max_population");
        ladybird_min_population =
                evts.getDouble("ladybird_min_population");

        addPredicates(this) +=
                P("TwoManyPlantlouse", &Smartgardener::TwoManyPlantlouse),
                P("NotToSmallLadybirdPopulation",
                        &Smartgardener::NotToSmallLadybirdPopulation);

        addFacts(this) +=
                F("x", &Smartgardener::x),
                F("y", &Smartgardener::y);

        addOutputFunctions(this) +=
                O("treat", &Smartgardener::treat);

        vle::utils::Package pack(context(), "vle.examples");
        std::string filePath = pack.getDataFile("Smartgardener.txt");
        std::ifstream fileStream(filePath.c_str());
        KnowledgeBase::plan().fill(fileStream);

    }
Esempio n. 24
0
    void use_2d_regular_graph_generator(const vle::devs::InitEventList& events)
    {
        vle::translator::regular_graph_generator::parameter param{
            std::bind(&Builder::regular_graph_generator_make_model,
                      this,
                      std::placeholders::_1,
                      std::placeholders::_2,
                      std::placeholders::_3),
            regular_graph_generator_connectivity()
        };

        vle::translator::regular_graph_generator rgg(param);

        int width_mask = events.getInt("mask-width");
        int height_mask = events.getInt("mask-height");
        vle::utils::Array<std::string> mask(width_mask, height_mask);

        const auto& v = events.getSet("mask").value();

        {
            if (vle::utils::numeric_cast<int>(mask.size()) !=
                width_mask * height_mask)
                throw vle::utils::ModellingError("mask definition error");

            int i = 0, j = 0;

            for (const auto& str : v) {
                mask(i, j) = str->toString().value();
                ++j;

                if (j >= height_mask) {
                    i++;
                    j = 0;
                }
            }
        }

        rgg.make_2d(*this,
                    { { events.getInt("width"), events.getInt("height") } },
                    { { events.getBoolean("wrap-width"),
                        events.getBoolean("wrap-height") } },
                    mask,
                    events.getInt("x-mask"),
                    events.getInt("y-mask"));
    }
Esempio n. 25
0
    CompareDateAI(const vle::devs::ExecutiveInit &init,
                  const vle::devs::InitEventList &evts)
        : vle::devs::Executive(init, evts)
    {
        vle::utils::Package package("safihr.cropmodel");

        initialize_date(package.getDataFile(evts.getString("filename")));

        std::sort(date.begin(), date.end(),
                  [] (const data& lhs,
                      const data& rhs)
                  {
                      return lhs.dmin < rhs.dmin;
                  });

        DTraceModel(vle::fmt("AI need to build: %1% models") % date.size());
        DTraceModel(vle::fmt("Table: %1%") % date);
    }
Esempio n. 26
0
    Builder(const vle::devs::ExecutiveInit& init,
            const vle::devs::InitEventList& events)
      : vle::devs::Executive(init, events)
    {
        model_prefix = events.getString("model-prefix");
        model_classname = events.getString("model-class");
        condition_name = events.getString("node-condition");
        graph_type = events.getString("graph-type");
        graph_connectivity = events.getString("graph-connectiviy");
        directed = events.getBoolean("graph-directed");

        if (graph_type == "graph")
            use_graph_generator(events);
        else if (graph_type == "regular")
            use_regular_graph_generator(events);
        else
            throw vle::utils::ModellingError("Unknown graph type %s",
                                             graph_type.c_str());
    }
Esempio n. 27
0
    AdaptativeQuantifier(const vd::DynamicsInit &init,
                         const vd::InitEventList &events)
        : vd::Dynamics(init, events)
    {
        const auto& my_list = getModel().getOutputPortList();

        if (not my_list.empty()) {
            m_output_port_label = (my_list.begin())->first;
            m_has_output_port = true;
        }

        if (my_list.size() > 1)
            Trace(context(), 6, "Warning: multiple output ports."
                  " Will use only port %s\n", m_output_port_label.c_str());

        m_adaptative = true;

        if (events.end() != events.find("allow_offsets")) {
            m_adaptative = vv::toBoolean(events.get("allow_offsets"));
        }

        if (m_adaptative) {
            m_adapt_state = POSSIBLE;
        } else {
            m_adapt_state = IMPOSSIBLE;
        }

        m_zero_init_offset = false;
        if (events.end() != events.find("zero_init_offset")) {
            m_zero_init_offset = vv::toBoolean(events.get("zero_init_offset"));
        }

        if (events.end() != events.find("quantum")) {
            m_step_size = vv::toDouble(events.get("quantum"));
        } else {
            Trace(context(), 6, "Warning : no quantum value provided for"
                  " Quantifier %s. Using default value (0.1)\n",
                  getModelName().c_str());

            m_step_size = 0.1;
        }

        if (0 >= m_step_size)
            throw vu::ModellingError("Bad quantum value (provided value : %f, "
                                     "should be strictly positive)",
                                     m_step_size);

        if (events.end() != events.find("archive_length")) {
            m_past_length = vv::toInteger(events.get("archive_length"));
        } else {
            m_past_length = 3;
        }

        if (2 >= m_past_length) {
            throw vu::ModellingError("Bad archive length value ( provided value"
                ": %u, should at least 3)", m_past_length);
        }
    }
Esempio n. 28
0
 ActivityScheduler(const vle::devs::DynamicsInit& init,
                   const vle::devs::InitEventList& events) :
     vle::devs::Dynamics(init, events),
     mActivities(events.get("activities"))
 {
 }
Esempio n. 29
0
 ConstantGenerator(const vle::devs::DynamicsInit &init,
                   const vle::devs::InitEventList &events)
     : vle::devs::Dynamics(init, events)
 {
     m_neighborhood = events.getInt("neighborhood");
 }