Exemplo n.º 1
0
 Texture2DResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
     ResourceTemplate<0, Texture2D>(manager, name, desc)
 {
     e = e == NULL ? desc->descriptor : e;
     TextureInternalFormat tf;
     TextureFormat f;
     PixelType t;
     Texture::Parameters params;
     Buffer::Parameters s;
     int w;
     int h;
     try {
         checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,minLod,maxLod,compare,borderType,borderr,borderg,borderb,bordera,maxAniso,width,height,");
         getIntParameter(desc, e, "width", &w);
         getIntParameter(desc, e, "height", &h);
         getParameters(desc, e, tf, f, t);
         getParameters(desc, e, params);
         s.compressedSize(desc->getSize());
         init(w, h, tf, f, t, params, s, CPUBuffer(desc->getData()));
         desc->clearData();
     } catch (...) {
         desc->clearData();
         throw exception();
     }
 }
Exemplo n.º 2
0
    HydroFlowProducerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
        ResourceTemplate<30, HydroFlowProducer>(manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        ptr<TileCache> cache;
        ptr<GraphProducer> graphs;
        int displayTileSize = 192;
        float slip = 1.0f;
        float searchRadiusFactor = 1.0f;
        float potentialDelta = 0.01f;
        int minLevel = 0;

        checkParameters(desc, e, "name,cache,graphs,displayTileSize,slip,searchRadiusFactor, potentialDelta,minLevel,");
        cache = manager->loadResource(getParameter(desc, e, "cache")).cast<TileCache>();
        graphs = manager->loadResource(getParameter(desc, e, "graphs")).cast<GraphProducer>();
        if (e->Attribute("displayTileSize") != NULL) {
            getIntParameter(desc, e, "displayTileSize", &displayTileSize);
        }
        if (e->Attribute("slip") != NULL) {
            getFloatParameter(desc, e, "slip", &slip);
        }
        if (e->Attribute("searchRadiusFactor") != NULL) {
            getFloatParameter(desc, e, "searchRadiusFactor", &searchRadiusFactor);
        }
        if (e->Attribute("potentialDelta") != NULL) {
            getFloatParameter(desc, e, "potentialDelta", &potentialDelta);
        }
        if (e->Attribute("minLevel") != NULL) {
            getIntParameter(desc, e, "minLevel", &minLevel);
        }

        init(graphs, cache, displayTileSize, slip, searchRadiusFactor, potentialDelta, minLevel);
    }
Exemplo n.º 3
0
 Texture3DResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
     ResourceTemplate<0, Texture3D>(manager, name, desc)
 {
     e = e == NULL ? desc->descriptor : e;
     TextureInternalFormat tf;
     TextureFormat f;
     PixelType t;
     Texture::Parameters params;
     Buffer::Parameters s;
     int w;
     int h;
     int d;
     try {
         checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,wrapr,minLod,maxLod,width,height,depth,");
         getIntParameter(desc, e, "width", &w);
         getIntParameter(desc, e, "height", &h);
         getIntParameter(desc, e, "depth", &d);
         if (h % d != 0) {
             if (Logger::ERROR_LOGGER != NULL) {
                 log(Logger::ERROR_LOGGER, desc, e, "Inconsistent 'height' and 'depth' attributes");
             }
             throw exception();
         }
         getParameters(desc, e, tf, f, t);
         getParameters(desc, e, params);
         s.compressedSize(desc->getSize());
         init(w, h / d, d, tf, f, t, params, s, CPUBuffer(desc->getData()));
         desc->clearData();
     } catch (...) {
         desc->clearData();
         throw exception();
     }
 }
Exemplo n.º 4
0
  RandomLfoPatch() : maxrate(getSampleRate()*2),
		     minrate(getSampleRate()/2000) {
    // noise = WhiteNoiseOscillator::create();
    noise = new WhiteNoiseOscillator();
    range = getFloatParameter("Range", 0.01, 1.0, 1.0);
    rate = getIntParameter("Rate", 0, maxrate, 0);
    scale = getIntParameter("Scale", 0, 5, 0);
    offset = getIntParameter("Root", -11, 12, 0);
    target = last = 0.0f;
  }
Exemplo n.º 5
0
/* Samples either one change point or one probability */
void sampleMixed(const gsl_rng *r,
		 parameters* p, int nPar,
		 intparameters *ip, int nIPar) {
  static int hello=1;
  double pr=gsl_rng_uniform(r);
  int moveK=pr<mixingRatio;
  const int *CDFdata=getData(), nCDFdata=getNdata();

  if(hello) fprintf(OUT, "sampleMixed()...\n"), hello=0;

  /* Set proposed changepoint locations and probabilities to current
     values.*/
  resetProposals(p, nPar, ip, nIPar);

  /* Assuming there is NO changepoint */
  if(nIPar<=0) moveK=0;
  if(moveK) {
    double pJump=0.1;
    /* Which k shall be moved? */
    int indK=gsl_rng_uniform_int(r, nIPar);
    int kDown=(indK-1>=0)?getIntParameter(ip,indK-1):0;
    int kUp=(indK+1<nIPar)?getIntParameter(ip,indK+1):getNdata();
    int kNew;
    int succ0, succ1;
    int fail0, fail1;
    double p0, p1;


    setIntMin(ip, indK, kDown);
    setIntMax(ip, indK, kUp);

    if(gsl_rng_uniform(r)>=pJump) {
      /*Move only one parameter by width */
      proposeIntConstrainedAB(r, ip, indK, 1);
    } else {
      proposeIntShiftInterval(r, ip, indK, 1);
    }
      /* Update probabilities */
      kNew=getIntProposal(ip,indK);

      succ0=succInterval(CDFdata, kDown, kNew);
      succ1=succInterval(CDFdata, kNew, kUp);
      fail0=kNew-kDown-succ0;
      fail1=kUp-kNew-succ1;
      p0=gsl_ran_beta(r, succ0, fail0);
      p1=gsl_ran_beta(r, succ1,fail1);

      setProposal(p, indK, p0);
      setProposal(p, indK+1, p1);
  }
  else {
    sampleProbabilities(r, CDFdata, nCDFdata, p, nPar, ip, nIPar);
  }
}
Exemplo n.º 6
0
    ForestOrthoLayerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc,
            const TiXmlElement *e = NULL) :
        ResourceTemplate<40, ForestOrthoLayer> (manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        ptr<GraphProducer>graphProducer;
        int displayLevel = 0;
        vec4f color = vec4f((float)30/255,(float)62/255,(float)45/255, 1.0f);

        checkParameters(desc, e, "name,graph,renderProg,level,color,quality,");
        string g = getParameter(desc, e, "graph");

        graphProducer = manager->loadResource(g).cast<GraphProducer>();
        if (e->Attribute("level") != NULL) {
            getIntParameter(desc, e, "level", &displayLevel);
        }
        if (e->Attribute("quality") != NULL) {
            quality = strcmp(e->Attribute("quality"), "true") == 0;
        }

        if (e->Attribute("color") != NULL) {
            string c = getParameter(desc, e, "color") + ",";
            string::size_type start = 0;
            string::size_type index;
            for (int i = 0; i < 3; i++) {
                index = c.find(',', start);
                color[i] = (float) atof(c.substr(start, index - start).c_str()) / 255;
                start = index + 1;
            }
        }

        ptr<Program> layerProgram = manager->loadResource(getParameter(desc, e, "renderProg")).cast<Program>();
        init(graphProducer, layerProgram, displayLevel, quality, color);
    }
Exemplo n.º 7
0
    TerrainNodeResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
        ResourceTemplate<0, TerrainNode>(manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        float size;
        float zmin;
        float zmax;
        ptr<Deformation> deform;
        float splitFactor;
        int maxLevel;
        checkParameters(desc, e, "name,size,zmin,zmax,deform,radius,splitFactor,horizonCulling,maxLevel,");
        getFloatParameter(desc, e, "size", &size);
        getFloatParameter(desc, e, "zmin", &zmin);
        getFloatParameter(desc, e, "zmax", &zmax);
        if (e->Attribute("deform") != NULL && strcmp(e->Attribute("deform"), "sphere") == 0) {
            deform = new SphericalDeformation(size);
        }
        if (e->Attribute("deform") != NULL && strcmp(e->Attribute("deform"), "cylinder") == 0) {
            float radius;
            getFloatParameter(desc, e, "radius", &radius);
            deform = new CylindricalDeformation(radius);
        }
        if (deform == NULL) {
            deform = new Deformation();
        }
        getFloatParameter(desc, e, "splitFactor", &splitFactor);
        getIntParameter(desc, e, "maxLevel", &maxLevel);

        ptr<TerrainQuad> root = new TerrainQuad(NULL, NULL, 0, 0, -size, -size, 2.0 * size, zmin, zmax);
        init(deform, root, splitFactor, maxLevel);

        if (e->Attribute("horizonCulling") != NULL && strcmp(e->Attribute("horizonCulling"), "false") == 0) {
            horizonCulling = false;
        }
    }
Exemplo n.º 8
0
    WaterElevationLayerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc,
            const TiXmlElement *e = NULL) :
        ResourceTemplate<40, WaterElevationLayer> (manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        ptr<GraphProducer> graphProducer;
        ptr<TileProducer> elevations;
        int displayLevel = 0;
        bool quality = true;
        bool deform = false;

        checkParameters(desc, e, "name,graph,renderProg,fillProg,level,cpuElevations,quality,deform,");

        string g = getParameter(desc, e, "graph");
        graphProducer = manager->loadResource(g).cast<GraphProducer>();

        string r = getParameter(desc, e, "cpuElevations");
        elevations = manager->loadResource(r).cast<TileProducer>();

        if (e->Attribute("level") != NULL) {
            getIntParameter(desc, e, "level", &displayLevel);
        }
        if (e->Attribute("quality") != NULL) {
            quality = strcmp(e->Attribute("quality"), "true") == 0;
        }
        if (e->Attribute("deform") != NULL) {
            deform = strcmp(e->Attribute("deform"), "true") == 0;
        }

        ptr<Program> layerProgram = manager->loadResource(getParameter(desc, e, "renderProg")).cast<Program>();
        ptr<Program> fillProg = manager->loadResource(getParameter(desc, e, "fillProg")).cast<Program>();
        init(graphProducer, layerProgram, fillProg, elevations, displayLevel, quality, deform);
    }
Exemplo n.º 9
0
    TextureCubeResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
        ResourceTemplate<0, TextureCube>(manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        TextureInternalFormat tf;
        TextureFormat f;
        PixelType t;
        Texture::Parameters params;
        Buffer::Parameters s[6];
        int w;
        int h;
        try {
            checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,minLod,maxLod,width,height,");
            getIntParameter(desc, e, "width", &w);
            getIntParameter(desc, e, "height", &h);
            if (h != 6 * w) {
                if (Logger::ERROR_LOGGER != NULL) {
                    log(Logger::ERROR_LOGGER, desc, e, "Inconsistent 'width' and 'height' attributes");
                }
                throw exception();
            }
            getParameters(desc, e, tf, f, t);
            getParameters(desc, e, params);

            int bpp = getFormatSize(f, t);

            ptr<Buffer> pixels[6];
            for (int i = 0; i < 6; ++i) {
                pixels[i] = new CPUBuffer(desc->getData() + i * w * w * bpp);
            }

            try {
                init(w, w, tf, f, t, params, s, pixels);
            } catch (...) {
                throw exception();
            }
            desc->clearData();
        } catch (...) {
            desc->clearData();
            throw exception();
        }
    }
Exemplo n.º 10
0
/* Selects changepoint position and adds new changepoint before or after */
void sampleDeath(const gsl_rng *r,
		 parameters* p, int actP, int nPar,
		 intparameters *ip, int actIP, int nIPar) {
  /* select change point that will be deleted */
  int kIndex=gsl_rng_uniform_int(r, actIP);
  int kDown, kUp;
  int succ, fail;
  /* Open probabilities that replaces probabilities 'left' and 'right'
     of deleted changepoint.*/
  double pNew;
  int i;
  static int hello=1;
  const int*CDF=getData(), nCDF=getNdata();
  double alpha=getAlpha(), beta=getBeta();

  if(hello) fprintf(OUT, "sampleDeath()\n"), hello=0;

  /*Copy kIndex parameters unchanged */
  copyIntOrg2Prop(ip, kIndex);

  /* Omit kIndex */
  for(i=kIndex; i<nIPar-1; i++) {
    setIntProposal(ip, i, getIntParameter(ip,i+1));
  }

  /*Copy kIndex double parameters unchanged */
  copyOrg2Prop(p, kIndex);

  kDown=(kIndex<=0)?0:getIntParameter(ip, kIndex-1);
  kUp=(kIndex==actIP)?nCDF-1:getIntParameter(ip,kIndex)-1;
  succ=succInterval(CDF, kDown, kUp), fail=failInterval(CDF, kDown, kUp);
  pNew=gsl_ran_beta(r, succ+alpha+1,fail+beta+1);
  setProposal(p, kIndex, pNew);

  /* Balance with corresponding birth move */
  proposalScale=(double)kUp-kDown;

  for(i=kIndex+1; i<nPar-1; i++) {
    setProposal(p, i, getParameter(p,i+1));
  }
}
Exemplo n.º 11
0
    GPUTileStorageResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
        ResourceTemplate<0, GPUTileStorage>(manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        int tileSize;
        int nTiles;
        TextureInternalFormat tf;
        TextureFormat f;
        PixelType t;
        Texture::Parameters params;
        bool useTileMap = false;
        checkParameters(desc, e, "name,tileSize,nTiles,tileMap,internalformat,format,type,min,mag,minLod,maxLod,minLevel,maxLevel,swizzle,anisotropy,");
        getParameters(desc, e, tf, f, t);
        getParameters(desc, e, params);
        getIntParameter(desc, e, "tileSize", &tileSize);
        getIntParameter(desc, e, "nTiles", &nTiles);
        if (e->Attribute("tileMap") != NULL) {
            useTileMap = strcmp(e->Attribute("tileMap"), "true") == 0;
        }

        init(tileSize, nTiles, tf, f, t, params, useTileMap);
    }
Exemplo n.º 12
0
 Texture2DArrayResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
     ResourceTemplate<0, Texture2DArray>(manager, name, desc)
 {
     e = e == NULL ? desc->descriptor : e;
     TextureInternalFormat tf;
     TextureFormat f;
     PixelType t;
     Texture::Parameters params;
     Buffer::Parameters s;
     int w;
     int h;
     int l;
     try {
         checkParameters(desc, e, "name,source,internalformat,format,type,min,mag,wraps,wrapt,minLod,maxLod,compare,borderType,borderr,borderg,borderb,bordera,maxAniso,width,height,depth,layers,");
         getIntParameter(desc, e, "width", &w);
         getIntParameter(desc, e, "height", &h);
         if (e->Attribute("depth") != NULL) {
             getIntParameter(desc, e, "depth", &l);
         } else {
             getIntParameter(desc, e, "layers", &l);
         }
         if (h % l != 0) {
             if (Logger::ERROR_LOGGER != NULL) {
                 log(Logger::ERROR_LOGGER, desc, e, "Inconsistent 'height' and 'layers' attributes");
             }
             throw exception();
         }
         getParameters(desc, e, tf, f, t);
         getParameters(desc, e, params);
         s.compressedSize(desc->getSize());
         init(w, h / l, l, tf, f, t, params, s, CPUBuffer(desc->getData()));
         desc->clearData();
     } catch (...) {
         desc->clearData();
         throw exception();
     }
 }
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
  char line[80];
  char *xs;
  double x;
  int which_bin;
  int i=0;

  instream = stdin;

  setCommandLineParameters(argc, argv);
  if (getFlagParam("-usage")){
    printf("usage:     dst2hst    -width [1.0]\n");
    printf("                      -n_bins [64]\n");
    printf("                      -start_x [0.0]\n");
    printf("                      \n");
    exit(0);
  }

  while (++i < argc)
  {
    if ((argc>1) && ((*argv[i]) != '-')) instream = fopen(argv[i], "r");
    else if (!strcmp(argv[i], "-width")) width = getDoubleParameter("width", argv[++i]);
    else if (!strcmp(argv[i], "-n_bins")) n_bins = getIntParameter("n_bins", argv[++i]);
    else if (!strcmp(argv[i], "-start_x")) start_x = getDoubleParameter("start_x", argv[++i]);
  }

  end_x = start_x + n_bins * width;

  while (1)
  {
    fgets(line, 80, instream);
    if (feof(instream)) break;

    xs = strtok(line, "\n");
    x = strtod(xs, NULL);

    if ((x < start_x) || (x > end_x)) fprintf(stderr, "%lf outside of range, discarding...\n", x);

    else
    {
      which_bin = (int)floor((x - start_x)/width);
      all_bins[which_bin]++;
    }

  }

  for (which_bin = 0; which_bin<n_bins; which_bin++) printf("%lf\t%d\n", start_x + which_bin*width, all_bins[which_bin]);
}
Exemplo n.º 14
0
    ParticleStorageResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc, const TiXmlElement *e = NULL) :
        ResourceTemplate<50, ParticleStorage>(manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        checkParameters(desc, e, "name,capacity,pack,");

        bool pack = true;
        int capacity;
        getIntParameter(desc, e, "capacity", &capacity);

        if (e->Attribute("pack") != NULL) {
            pack = strcmp(e->Attribute("pack"), "true") == 0;
        }

        init(capacity, pack);

    }
Exemplo n.º 15
0
int main(int argc, char *argv[])
{
    int i=0;
    double old_energy, new_energy;
    double delta_energy;
    double boltzmann_factor;
    double the_exponential;
    int monte_carlo_steps;
    int trial_number;
    double x0, y0, z0;
    double dx, dy, dz;
    double rvlen;

    double sum_dx, sum_dy, sum_dz;

    instream = stdin;

    while (++i < argc)
    {
        if ((argc>1) && (*argv[i] != '-')) instream = fopen(argv[i], "r");
        else if (!strcmp(argv[i], "-v")) verbose = 1;
        else if (!strcmp(argv[i], "-T")) temperature = getDoubleParameter("temperature", argv[++i]);
        else if (!strcmp(argv[i], "-dim"))
        {
            box_x = getDoubleParameter("box_x", argv[++i]);
            box_y = getDoubleParameter("box_y", argv[++i]);
            box_z = getDoubleParameter("box_z", argv[++i]);
        }
        else if (!strcmp(argv[i], "-n_trials")) n_trials = getDoubleParameter("n_trials", argv[++i]);
        else if (!strcmp(argv[i], "-rng_seed")) rng_seed = getIntParameter("rng_seed", argv[++i]);
        else if (!strcmp(argv[i], "-n_steps")) n_steps = getIntParameter("n_steps", argv[++i]);
        else if (!strcmp(argv[i], "-randomize")) rng_seed = getRandomSeed();
        else if (!strcmp(argv[i], "-perturbation_length")) perturbation_length = getDoubleParameter("perturbation_length", argv[++i]);
    }

    initializeRandomNumberGeneratorTo(rng_seed);
    loadConfiguration();

    for (trial_number = 0; trial_number < n_trials; trial_number++)
    {
        sum_dx = 0;
        sum_dy = 0;
        sum_dz = 0;
        V printf("trial number %d\n", trial_number);
        accepted_moves = 0;

        // pick starting point
        x0 = x[number_of_molecules] = box_x * rnd();
        y0 = y[number_of_molecules] = box_y * rnd();
        z0 = z[number_of_molecules] = box_z * rnd();

        // move it a bunch of times
        for(monte_carlo_steps=0; monte_carlo_steps<n_steps; monte_carlo_steps++)
        {
            dx = 2*(rnd() - .5);
            dy = 2*(rnd() - .5);
            dz = 2*(rnd() - .5);

            rvlen = perturbation_length / sqrt(dx*dx + dy*dy + dz*dz);
            dx *= rvlen;
            dy *= rvlen;
            dz *= rvlen;

            // try out the new position
            old_energy = calculateSystemEnergy();

            x[number_of_molecules] += dx;
            y[number_of_molecules] += dy;
            z[number_of_molecules] += dz;
            adjustForBoundary(number_of_molecules);

            new_energy = calculateSystemEnergy();
            delta_energy = new_energy - old_energy;

            if (delta_energy <= 0)
            {
                accepted_moves++;
                sum_dx += dx;
                sum_dy += dy;
                sum_dz += dz;
                continue; /* move accepted */
            }

            the_exponential = 0.0 - delta_energy/temperature;

            if (the_exponential > -75)
            {
                boltzmann_factor = exp(the_exponential);
                if (boltzmann_factor > rnd())
                {
                    accepted_moves++;
                    sum_dx += dx;
                    sum_dy += dy;
                    sum_dz += dz;
                    continue; /* move accepted */
                }
            }

            /* move rejected: */
            x[number_of_molecules] -= dx;
            y[number_of_molecules] -= dy;
            z[number_of_molecules] -= dz;
            adjustForBoundary(number_of_molecules);
        }

        // look at end point, compare

        total_translation = sqrt(sum_dx*sum_dx + sum_dy*sum_dy + sum_dz*sum_dz);

        printf("%lf\n", total_translation);
        V printf("%lf\t%lf\t%lf\t%lf\n", sum_dx, sum_dy, sum_dz, total_translation);
        V printf("acceptance ratio:  %lf\n", (0.0 + accepted_moves)/n_steps);
    }

    return 0;
} /* end main */
Exemplo n.º 16
0
    TextureOrthoLayerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc,
            const TiXmlElement *e = NULL) :
        ResourceTemplate<40, TextureLayer> (manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;

        checkParameters(desc, e, "name,producer,renderProg,tileSamplerName,storeTiles,equation,sourceFunction,destinationFunction,equationAlpha,sourceFunctionAlpha,destinationFunctionAlpha,level,");

        ptr<Object> programRessource = manager->loadResource(getParameter(desc, e, "renderProg"));
        assert(programRessource != NULL);
        ptr<Program> program = programRessource.cast<Program>();
        assert(program != NULL);

        ptr<TileProducer> tiles = manager->loadResource(getParameter(desc, e, "producer")).cast<TileProducer>();
        assert(tiles != NULL);

        std::string tileSamplerName = getParameter(desc, e, "tileSamplerName");
        assert(tileSamplerName != "");

        BlendParams blendParams;
        blendParams.rgb = ADD;
        blendParams.srgb = SRC_ALPHA;
        blendParams.drgb = ONE_MINUS_SRC_ALPHA;
        blendParams.alpha = ADD;
        blendParams.salpha = SRC_ALPHA;
        blendParams.dalpha = ONE_MINUS_SRC_ALPHA;
        const char *c = e->Attribute("buffer");
        if (c != NULL) {
            if (strcmp(c, "COLOR0") == 0) {
                blendParams.buffer = COLOR0;
            } else if (strcmp(c, "COLOR1") == 0) {
                blendParams.buffer = COLOR1;
            } else if (strcmp(c, "COLOR2") == 0) {
                blendParams.buffer = COLOR2;
            } else if (strcmp(c, "COLOR3") == 0) {
                blendParams.buffer = COLOR3;
            } else if (strcmp(c, "DEPTH") == 0) {
                blendParams.buffer = DEPTH;
            } else if (strcmp(c, "STENCIL") == 0) {
                blendParams.buffer = STENCIL;
            }
        }
        if (e->Attribute("equation") != NULL) {
            blendParams.rgb = getBlendEquation(desc, e, "equation");
            blendParams.srgb = getBlendArgument(desc, e, "sourceFunction");
            blendParams.drgb = getBlendArgument(desc, e, "destinationFunction");
        }
        if (e->Attribute("equationAlpha") != NULL) {
            blendParams.alpha = getBlendEquation(desc, e, "equationAlpha");
            blendParams.salpha = getBlendArgument(desc, e, "sourceFunctionAlpha");
            blendParams.dalpha = getBlendArgument(desc, e, "destinationFunctionAlpha");
        }

        int displayLevel = 0;
        if (e->Attribute("level") != NULL) {
            getIntParameter(desc, e, "level", &displayLevel);
        }

        bool storeTiles = false;
        if (e->Attribute("storeTiles") != NULL) {
            storeTiles = strcmp(e->Attribute("storeTiles"), "true") == 0;
        }

        init(tiles, program, tileSamplerName, blendParams, displayLevel, storeTiles);
    }
Exemplo n.º 17
0
  void
  RobotSetup::addNWays()
  {

    int do_quick;
    options()->GetEnumValue("do_a_quick_one", do_quick, prefix());
    int depth_frac;
    options()->GetIntegerValue("branch_on_frac_only", depth_frac, prefix());

    // pass user set Sos constraints (code inspired from CoinSolve.cpp)
    const TMINLP::SosInfo * sos = nonlinearSolver()->model()->sosConstraints();
    if (!getIntParameter(BabSetupBase::DisableSos) && sos && sos->num > 0) //we have some sos constraints
    {
      const int & numSos = sos->num;
      OsiObject ** objects = new OsiObject*[numSos];
      const int * starts = sos->starts;
      const int * indices = sos->indices;
      //const char * types = sos->types;
      const double * weights = sos->weights;
      bool hasPriorities = false;
      const int * varPriorities = nonlinearSolver()->getPriorities();
      int numberObjects =  nonlinearSolver()->numberObjects();
      if (varPriorities)
      {
        for (int i = 0 ; i < numberObjects ; i++) {
          if (varPriorities[i]) {
            hasPriorities = true;
            break;
          }
        }
      }
      const int * sosPriorities = sos->priorities;
      if (sosPriorities)
      {
        for (int i = 0 ; i < numSos ; i++) {
          if (sosPriorities[i]) {
            hasPriorities = true;
            break;
          }
        }
      }

      std::vector<std::list<int> > groups(numSos + 1);

      for (int i = 0 ; i < numSos ; i++)
      {
        int start = starts[i];
        int length = starts[i + 1] - start;
          for(int j = 0 ; j < length ; j++){
              groups[(size_t) weights[j]].push_back(indices[start+j]);
          }
      }

      for (int i = 0 ; i < numSos ; i++)
      {
        int start = starts[i];
        int length = starts[i + 1] - start;
          BonNWayObject * nway = new BonNWayObject(length, &indices[start],i);
          nway->setPriority(1);
          for(int j = 0 ; j < length ; j++){//Setup consequences
             n_way_consequences cons;
             std::vector<int>& ids = cons.indices;
             int idx = (int) weights[j];
             const std::list<int> &to_add = groups[idx];
             for(std::list<int>::const_iterator k = to_add.begin() ; 
                 k != to_add.end() ; k++){
               if(*k != indices[start+j]) ids.push_back(*k);
             }
           nway->setConsequence(j, cons);
          }
          objects[i] = nway;

        if(do_quick)
          nway->make_quick();
        nway->set_only_frac_branches(depth_frac);
        if (hasPriorities && sosPriorities && sosPriorities[i]) {
          objects[i]->setPriority(sosPriorities[i]);
        }
      }
      nonlinearSolver()->addObjects(numSos, objects);
      for (int i = 0 ; i < numSos ; i++)
        delete objects[i];
      delete [] objects;
    }
  }
Exemplo n.º 18
0
std::string ProtocolComen::getStringForMethod(int method, unsigned char level, Controller *) {
	int intHouse = getIntParameter(L"house", 1, 33554431);
	intHouse <<= 1; //They seem to only accept even codes?
	int intCode = getIntParameter(L"unit", 1, 16)-1;
	return getStringSelflearningForCode(intHouse, intCode, method, level);
}
Exemplo n.º 19
0
Control::Control( int argc, char** argv ) {

	// parse the command line options to set all vars

	if( ( argc % 2 == 0 ) || ( argc == 1 ) ) {
		cerr << "Parse error: Number of command line parameters incorrect\n";
		cerr << "Usage:" << endl;
		cerr << argv[ 0 ] << " -i InputFile [-o OutputFile] [-n NumberOfTries] [-s RandomSeed] [-t TimeLimit] [-p ProblemType]" << endl;
		exit(1);
	}
	
	for( int i = 1; i < argc / 2 + 1; i++ ) {
		parameters[ argv[ i * 2 - 1 ] ] = argv[ i * 2 ];
	}
	
	nrTry = 0;
	
	// check for input parameter
	
	if( parameterExists( "-i") ) {
		is = new ifstream( getStringParameter( "-i" ).c_str() );
	} else {
		cerr << "Error: No input file given, exiting" << endl;
		cerr << "Usage:" << endl;
		cerr << argv[ 0 ] << " -i InputFile [-o OutputFile] [-n NumberOfTries] [-s RandomSeed] [-t TimeLimit] [-p ProblemType]" << endl;
		exit(1);
	}
	
	// check for ouput parameter
	
	if( parameterExists( "-o" ) ) {
		os = new ofstream( getStringParameter( "-o" ).c_str() );
	} else {
		cerr << "Warning: No output file given, writing to stdout" << endl;
		os = &cout;
	}
	
	// check for number of tries parameter
	
	if( parameterExists( "-n" ) ) {
		maxTry = getIntParameter( "-n" );
		cout << "Max number of tries " << maxTry << endl;
	} else {
		cerr << "Warning: Number of tries is set to default (10)" << endl;
		maxTry = 10; // default number of tries
	}

	// check for time limit parameter
	
	if( parameterExists( "-t" ) ) {
		timeLimit = getDoubleParameter( "-t" );
		cout <<"Time limit " << timeLimit << endl;
	} else {
		cerr << "Warning: Time limit is set to default (90 sec)" << endl;
		timeLimit = 90; // default time limit
	}

        // check for problem instance type parameter for the local search

	if( parameterExists( "-p" ) ) {
		problemType = getIntParameter( "-p" );
		cout <<"Problem instance type " << problemType << endl;
	} else {
	  //cerr << "Warning: The problem instance type is set by default to 1 (easy)" << endl;
		problemType = 1; // default problem type
	}


        // check for maximum steps parameter for the local search
	
	if( parameterExists( "-m" ) ) {
		maxSteps = getIntParameter( "-m" );
		cout <<"Max number of steps in the local search " << maxSteps << endl;
	} else {
	  //cerr << "Warning: The maximum number of steps for the local search is set by default to 100" << endl;
		maxSteps = 100; // default max steps
	}

        // check for time limit parameter for the local search
	
	if( parameterExists( "-l" ) ) {
		LS_limit = getDoubleParameter( "-l" );
		cout <<"Local search time limit " << LS_limit << endl;
	} else {
		cerr << "Warning: The local search time limit is set to default (99999 sec)" << endl;
		LS_limit = 99999; // default local search time limit
	}

        // check for probability parameter for each move in the local search
	
	if( parameterExists( "-p1" ) ) {
		prob1 = getDoubleParameter( "-p1" );
		cout << "LS move 1 probability " << prob1 <<endl;
	} else {
		cerr << "Warning: The local search move 1 probability is set to default 1.0" << endl;
		prob1 = 1.0; // default local search probability for each move of type 1 to be performed
	}

	if( parameterExists( "-p2" ) ) {
		prob2 = getDoubleParameter( "-p2" );
		cout <<"LS move 2 probability " << prob2 << endl;
	} else {
		cerr << "Warning: The local search move 2 probability is set to default 1.0" << endl;
		prob2 = 1.0; // default local search probability for each move to be performed
	}

	if( parameterExists( "-p3" ) ) {
		prob3 = getDoubleParameter( "-p3" );
		cout <<"LS move 3 probability " << prob3 <<  endl;
	} else {
		cerr << "Warning: The local search move 3 probability is set to default 0.0" << endl;
		prob3 = 0.0; // default local search probability for each move to be performed
	}

	// check for random seed
	
	if( parameterExists( "-s" ) ) {
		seed = getIntParameter( "-s" );
		srand( seed );
	} else {
		seed = time( NULL );
		cerr << "Warning: " << seed << " used as default random seed" << endl;
		srand( seed );
	}
}
Exemplo n.º 20
0
/* Selects changepoint position and adds new changepoint before or after */
void sampleBirth(const gsl_rng *r,
		 parameters* p, int actP, int nPar,
		 intparameters *ip, int actIP, int nIPar) {
  /* select parameter */
  int kIndex=gsl_rng_uniform_int(r, actIP+1);
  int kDown=(kIndex<=0)?0:getIntParameter(ip,kIndex-1);
  int kUp=(kIndex==actIP)?getNdata()-1:getIntParameter(ip,kIndex)-1;

  /*sample new change point*/
  int kNew;
  int i;
  static int hello=1;
  const int *CDF=getData(), nCDF=getNdata();
  int succ0, succ1, fail0, fail1;
  double p0, p1;
  double alpha=getAlpha(), beta=getBeta();

  /* Adding the first changepoint */
  if(actIP==0) {
    /* k must be between 1 and nCDF-1*/
    int kNew=gsl_rng_uniform_int(r,nCDF-1)+1;

    /* Successes and failures before and after new changepoint kNew
       are used for sampling p0 and p1... */
    succ0=succInterval(CDF, 0, kNew), fail0=failInterval(CDF, 0, kNew);
    succ1=succInterval(CDF, kNew, nCDF), fail1=failInterval(CDF, kNew, nCDF);

    /* ... from beta distributions. */
    p0=gsl_ran_beta(r, succ0+1+alpha, fail0+beta+1);
    p1=gsl_ran_beta(r, succ1+1+alpha, fail1+beta+1);

    /* Set new proposal */
    setIntProposal(ip, 0, kNew);
    setProposal(p,0,p0);
    setProposal(p,1,p1);

    /* Balance with corresponding death move */
    proposalScale=1/((double)(nCDF-1));
    return;
  }

  /* Find kUp and kDown that are more than one data point apart. */
  while(kUp-kDown<=1) {
    kIndex=gsl_rng_uniform_int(r, actIP+1);
    kDown=(kIndex<=0)?0:getIntParameter(ip,kIndex-1);
    kUp=(kIndex==actIP)?getNdata()-1:getIntParameter(ip,kIndex)-1;
  }

  /* Balance with corresponding death move */
  proposalScale=1/((double)(kUp-kDown));

  do {
    kNew=kDown+gsl_rng_uniform_int(r, kUp-kDown);
  }while (kNew==0);

  if(hello) fprintf(OUT, "sampleBirth()\n"), hello=0;

  /*Copy kIndex parameters unchanged */
  copyIntOrg2Prop(ip, kIndex);

  /* Insert new changepoint */
  setIntProposal(ip, kIndex, kNew);

  /* Shift changepoints after inserted changepoint. */
  for(i=kIndex+1; i<nIPar; i++) {
    setIntProposal(ip, i, getIntParameter(ip,i-1));
  }

  /* Now copy kIndex open probabilities. */
  if(kIndex-1>0) copyOrg2Prop(p, kIndex);

  /* Sample open probabilities for the segments 'left' and 'right' of
     the new changepoint. */
  succ0=succInterval(CDF, kDown, kNew), fail0=failInterval(CDF, kDown, kNew);
  succ1=succInterval(CDF, kNew, kUp), fail1=failInterval(CDF, kNew, kUp);
  p0=gsl_ran_beta(r, succ0+alpha+1, fail0+beta+1);
  p1=gsl_ran_beta(r, succ1+alpha+1, fail1+beta+1);

  setProposal(p, kIndex, p0);
  setProposal(p, kIndex+1, p1);

  /* Shift the remaining open probabilities. */
  for(i=kIndex+2; i<nPar; i++) {
    double pI=getParameter(p,i-1);
    setProposal(p, i, pI);
  }
}