本文整理汇总了C++中Grid类的典型用法代码示例。如果您正苦于以下问题:C++ Grid类的具体用法?C++ Grid怎么用?C++ Grid使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Grid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateVerletList
void updateVerletList(const string &verletStringId,
Particles & particles,
Grid & grid,
double radius)
{
double radiusSquared = radius*radius;
int verletId = particles.getVerletId(verletStringId);
const unordered_map<int, GridPoint*> &gridpoints = grid.gridpoints();
const mat & R = particles.r();
const vector<int> &mygridPoints = grid.myGridPoints();
particles.clearVerletList(verletId);
#ifdef USE_OPENMP
#pragma omp parallel for
#endif
for(int i=0; i<mygridPoints.size(); i++)
{
double dx, dy, dz;
int gridId = mygridPoints.at(i);
const GridPoint & gridPoint = *gridpoints.at(gridId);
for(const pair<int, int> & idCol_i:gridPoint.particles())
{
int id_i = idCol_i.first;
vector<int> verletList;
const vec & r_i = R.col(idCol_i.second);
for(const pair<int, int> & idCol_j:gridPoint.particles())
{
int id_j = idCol_j.first;
if(id_i == id_j)
continue;
const vec & r_j = R.col(idCol_j.second);
dx = r_i(0) - r_j(0);
dy = r_i(1) - r_j(1);
dz = r_i(2) - r_j(2);
double drSquared = dx*dx + dy*dy + dz*dz;
if(drSquared < radiusSquared)
{
verletList.push_back(id_j);
}
}
// Neighbouring cells
const vector<GridPoint*> & neighbours = gridPoint.neighbours();
for(const GridPoint *neighbour:neighbours)
{
for(const pair<int, int> & idCol_j:neighbour->particles())
{
const vec & r_j = R.col(idCol_j.second);
dx = r_i(0) - r_j(0);
dy = r_i(1) - r_j(1);
dz = r_i(2) - r_j(2);
double drSquared = dx*dx + dy*dy + dz*dz;
if(drSquared < radiusSquared)
{
verletList.push_back(idCol_j.first);
}
}
}
#ifdef USE_OPENMP
#pragma omp critical
{
particles.setVerletList(id_i, verletList, verletId);
}
#else
particles.setVerletList(id_i, verletList, verletId);
#endif
}
}
}
示例2: A
void TestGemm
( Orientation orientA, Orientation orientB,
Int m, Int n, Int k, T alpha, T beta, const Grid& g,
bool print, bool correctness )
{
double startTime, runTime, realGFlops, gFlops;
DistMatrix<T> A(g), B(g), COrig(g), C(g);
if( orientA == NORMAL )
Uniform( A, m, k );
else
Uniform( A, k, m );
if( orientB == NORMAL )
Uniform( B, k, n );
else
Uniform( B, n, k );
Uniform( COrig, m, n );
if( print )
{
Print( A, "A" );
Print( B, "B" );
Print( COrig, "COrig" );
}
// Test the variant of Gemm that keeps A stationary
C = COrig;
if( g.Rank() == 0 )
cout << "Stationary A Algorithm:" << endl;
mpi::Barrier( g.Comm() );
startTime = mpi::Time();
Gemm( orientA, orientB, alpha, A, B, beta, C, GEMM_SUMMA_A );
mpi::Barrier( g.Comm() );
runTime = mpi::Time() - startTime;
realGFlops = 2.*double(m)*double(n)*double(k)/(1.e9*runTime);
gFlops = ( IsComplex<T>::val ? 4*realGFlops : realGFlops );
if( g.Rank() == 0 )
{
cout << " Time = " << runTime << " seconds. GFlops = "
<< gFlops << endl;
}
if( print )
{
ostringstream msg;
msg << "C := " << alpha << " A B + " << beta << " C";
Print( C, msg.str() );
}
if( correctness )
TestCorrectness( orientA, orientB, alpha, A, B, beta, COrig, C, print );
// Test the variant of Gemm that keeps B stationary
C = COrig;
if( g.Rank() == 0 )
cout << "Stationary B Algorithm:" << endl;
mpi::Barrier( g.Comm() );
startTime = mpi::Time();
Gemm( orientA, orientB, alpha, A, B, beta, C, GEMM_SUMMA_B );
mpi::Barrier( g.Comm() );
runTime = mpi::Time() - startTime;
realGFlops = 2.*double(m)*double(n)*double(k)/(1.e9*runTime);
gFlops = ( IsComplex<T>::val ? 4*realGFlops : realGFlops );
if( g.Rank() == 0 )
{
cout << " Time = " << runTime << " seconds. GFlops = "
<< gFlops << endl;
}
if( print )
{
ostringstream msg;
msg << "C := " << alpha << " A B + " << beta << " C";
Print( C, msg.str() );
}
if( correctness )
TestCorrectness( orientA, orientB, alpha, A, B, beta, COrig, C, print );
// Test the variant of Gemm that keeps C stationary
C = COrig;
if( g.Rank() == 0 )
cout << "Stationary C Algorithm:" << endl;
mpi::Barrier( g.Comm() );
startTime = mpi::Time();
Gemm( orientA, orientB, alpha, A, B, beta, C, GEMM_SUMMA_C );
mpi::Barrier( g.Comm() );
runTime = mpi::Time() - startTime;
realGFlops = 2.*double(m)*double(n)*double(k)/(1.e9*runTime);
gFlops = ( IsComplex<T>::val ? 4*realGFlops : realGFlops );
if( g.Rank() == 0 )
{
cout << "DONE. " << endl
<< " Time = " << runTime << " seconds. GFlops = "
<< gFlops << endl;
}
if( print )
{
ostringstream msg;
msg << "C := " << alpha << " A B + " << beta << " C";
Print( C, msg.str() );
}
if( correctness )
TestCorrectness( orientA, orientB, alpha, A, B, beta, COrig, C, print );
//.........这里部分代码省略.........
示例3: PROFILE3
void CCmpPathfinder::TerrainUpdateHelper(bool expandPassability)
{
PROFILE3("TerrainUpdateHelper");
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSimContext(), SYSTEM_ENTITY);
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
CTerrain& terrain = GetSimContext().GetTerrain();
if (!cmpTerrain || !cmpObstructionManager)
return;
u16 terrainSize = cmpTerrain->GetTilesPerSide();
if (terrainSize == 0)
return;
if (!m_TerrainOnlyGrid || m_MapSize != terrainSize)
{
m_MapSize = terrainSize;
SAFE_DELETE(m_TerrainOnlyGrid);
m_TerrainOnlyGrid = new Grid<NavcellData>(m_MapSize * Pathfinding::NAVCELLS_PER_TILE, m_MapSize * Pathfinding::NAVCELLS_PER_TILE);
}
Grid<u16> shoreGrid = ComputeShoreGrid();
// Compute initial terrain-dependent passability
for (int j = 0; j < m_MapSize * Pathfinding::NAVCELLS_PER_TILE; ++j)
{
for (int i = 0; i < m_MapSize * Pathfinding::NAVCELLS_PER_TILE; ++i)
{
// World-space coordinates for this navcell
fixed x, z;
Pathfinding::NavcellCenter(i, j, x, z);
// Terrain-tile coordinates for this navcell
int itile = i / Pathfinding::NAVCELLS_PER_TILE;
int jtile = j / Pathfinding::NAVCELLS_PER_TILE;
// Gather all the data potentially needed to determine passability:
fixed height = terrain.GetExactGroundLevelFixed(x, z);
fixed water;
if (cmpWaterManager)
water = cmpWaterManager->GetWaterLevel(x, z);
fixed depth = water - height;
// Exact slopes give kind of weird output, so just use rough tile-based slopes
fixed slope = terrain.GetSlopeFixed(itile, jtile);
// Get world-space coordinates from shoreGrid (which uses terrain tiles)
fixed shoredist = fixed::FromInt(shoreGrid.get(itile, jtile)).MultiplyClamp(TERRAIN_TILE_SIZE);
// Compute the passability for every class for this cell
NavcellData t = 0;
for (PathfinderPassability& passability : m_PassClasses)
if (!passability.IsPassable(depth, slope, shoredist))
t |= passability.m_Mask;
m_TerrainOnlyGrid->set(i, j, t);
}
}
// Compute off-world passability
// WARNING: CCmpRangeManager::LosIsOffWorld needs to be kept in sync with this
const int edgeSize = 3 * Pathfinding::NAVCELLS_PER_TILE; // number of tiles around the edge that will be off-world
NavcellData edgeMask = 0;
for (PathfinderPassability& passability : m_PassClasses)
edgeMask |= passability.m_Mask;
int w = m_TerrainOnlyGrid->m_W;
int h = m_TerrainOnlyGrid->m_H;
if (cmpObstructionManager->GetPassabilityCircular())
{
for (int j = 0; j < h; ++j)
{
for (int i = 0; i < w; ++i)
{
// Based on CCmpRangeManager::LosIsOffWorld
// but tweaked since it's tile-based instead.
// (We double all the values so we can handle half-tile coordinates.)
// This needs to be slightly tighter than the LOS circle,
// else units might get themselves lost in the SoD around the edge.
int dist2 = (i*2 + 1 - w)*(i*2 + 1 - w)
+ (j*2 + 1 - h)*(j*2 + 1 - h);
if (dist2 >= (w - 2*edgeSize) * (h - 2*edgeSize))
m_TerrainOnlyGrid->set(i, j, m_TerrainOnlyGrid->get(i, j) | edgeMask);
}
}
}
else
{
for (u16 j = 0; j < h; ++j)
for (u16 i = 0; i < edgeSize; ++i)
//.........这里部分代码省略.........
示例4: strcpy
MAD::MAD(Grid **grid_) {
ifc_polygon = NULL;
river_polygon = NULL;
ascii_grids = NULL;
spp_polygon = NULL;
PetscReal mx = 1.;
PetscReal my = 1.;
PetscReal mz = 1.;
PetscInt nx, ny, nz;
char filename[1024];
PetscBool option_found;
strcpy(filename,"mdt.in");
PetscOptionsGetString(PETSC_NULL,"-mdtin",filename,1024,&option_found);
FileIO *file = new FileIO(filename);
file->getLine();
file->readInt(&nx);
file->readInt(&ny);
file->readInt(&nz);
delete file;
PetscReal dx;
PetscReal dy;
PetscReal dz;// */
PetscReal len_x = 120.;
PetscReal len_y = 122;
PetscReal len_z = 60.;
dx = len_x/(PetscReal)nx;
dy = len_y/(PetscReal)ny;
dz = len_z/(PetscReal)nz;
PetscInt n = nx*ny*nz;
PetscPrintf(PETSC_COMM_WORLD,"nx = %d, dx = %f, lenx = %f\n",nx,dx,nx*dx);
PetscPrintf(PETSC_COMM_WORLD,"ny = %d, dy = %f, leny = %f\n",ny,dy,ny*dy);
PetscPrintf(PETSC_COMM_WORLD,"nz = %d, dz = %f, lenz = %f\n",nz,dz,nz*dz);
*grid_ = new Grid(nx,ny,nz);
Grid *grid = *grid_;
// grid spacing with a bias
#if 0
PetscReal sum_x = 0.;
PetscReal sum_y = 0.;
dx = 0.8470329472543
PetscReal *dx_array = new double[nx];
PetscReal *dy_array = new double[ny];
PetscReal *dz_array = new double[nz];
for (int i=0; i<nx; i++)
dx_array[i] = 10.;
for (int i=0; i<ny; i++)
dy_array[i] = 10.;
for (int i=0; i<nz; i++)
dz_array[i] = 0.25;
for (int i=11; i<19; i++) {
dx_array[i] = 10.*pow(1.30242241518419,(double)(10-i));
sum_x += dx_array[i];
}
for (int i=19; i<89; i++) {
dx_array[i] = 1.;
sum_x += dx_array[i];
}
for (int i=89; i<97; i++) {
dx_array[i] = 10.*pow(1.30242241518419,(double)(i-97));
sum_x += dx_array[i];
}
for (int i=97; i<9; i++) {
dy_array[110+i] = 10.*pow(1.353088,i+1.);
dy_array[9-i] = 10.*pow(1.353088,i+1.);
sum_y += dy_array[9-i];
}
grid->setGridSpacing(dx_array,dy_array,dz_array);
#else
grid->setGridSpacing(dx,dy,dz);
#endif
// grid->setOrigin(593618.9,114565.1,70.);
grid->setRotation(34.); // must come before ->setOrigin()
grid->setOrigin(594237.2891,115984.7447,70.);
// grid->computeCoordinates();
// grid->computeConnectivity();
grid->computeCellMapping();
grid->setUpCells();
grid->computeVertexMapping();
grid->setUpVertices();
grid->mapVerticesToCells();
ifc_polygon = new Polygon();
ifc_polygon->createIFCPolygon();
//.........这里部分代码省略.........
示例5: main
int main(int argc, char** argv) {
cl::ParseCommandLineOptions(argc, argv, "Rician3D example");
ElementType *Ty = new FP32Type();
Grid *GD = new Grid(3);
Field *U = new Field(GD, Ty, "U");
Field *G = new Field(GD, Ty, "G");
Field *F = new Field(GD, Ty, "F");
Field *R = new Field(GD, Ty, "R");
FP32Constant *ConstOne = new FP32Constant(1.0);
FP32Constant *Epsilon = new FP32Constant(1.0e-20);
FP32Constant *Sigma = new FP32Constant(1.0000001);
FP32Constant *Lambda = new FP32Constant(1.0000001);
Expression *Sigma2 = new BinaryOp(BinaryOp::MUL, Sigma, Sigma);
Expression *Gamma = new BinaryOp(BinaryOp::DIV, Lambda, Sigma2);
FP32Constant *C1 = new FP32Constant(2.38944);
FP32Constant *C2 = new FP32Constant(0.950037);
FP32Constant *C3 = new FP32Constant(4.65314);
FP32Constant *C4 = new FP32Constant(2.57541);
FP32Constant *C5 = new FP32Constant(1.48937);
FP32Constant *DT = new FP32Constant(5.0);
IntConstant *Offsets[3];
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(0);
Expression *U_0_0_0 = new FieldRef(U, 3, Offsets);
Offsets[0] = new IntConstant(1);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(0);
Expression *U_p1_0_0 = new FieldRef(U, 3, Offsets);
Offsets[0] = new IntConstant(-1);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(0);
Expression *U_m1_0_0 = new FieldRef(U, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(1);
Offsets[2] = new IntConstant(0);
Expression *U_0_p1_0 = new FieldRef(U, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(-1);
Offsets[2] = new IntConstant(0);
Expression *U_0_m1_0 = new FieldRef(U, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(1);
Expression *U_0_0_p1 = new FieldRef(U, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(-1);
Expression *U_0_0_m1 = new FieldRef(U, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(0);
Expression *G_0_0_0 = new FieldRef(G, 3, Offsets);
Offsets[0] = new IntConstant(1);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(0);
Expression *G_p1_0_0 = new FieldRef(G, 3, Offsets);
Offsets[0] = new IntConstant(-1);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(0);
Expression *G_m1_0_0 = new FieldRef(G, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(1);
Offsets[2] = new IntConstant(0);
Expression *G_0_p1_0 = new FieldRef(G, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(-1);
Offsets[2] = new IntConstant(0);
Expression *G_0_m1_0 = new FieldRef(G, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(1);
Expression *G_0_0_p1 = new FieldRef(G, 3, Offsets);
Offsets[0] = new IntConstant(0);
Offsets[1] = new IntConstant(0);
Offsets[2] = new IntConstant(-1);
Expression *G_0_0_m1 = new FieldRef(G, 3, Offsets);
//.........这里部分代码省略.........
示例6: convert_xmlelement_to_widget
//.........这里部分代码省略.........
bool bottom = bool_attr_is_true(elem, "bottom");
widget->setAlign((center ? JI_CENTER:
(right ? JI_RIGHT: JI_LEFT)) |
(top ? JI_TOP:
(bottom ? JI_BOTTOM: JI_MIDDLE)));
}
}
/* combobox */
else if (ustrcmp(elem_name, "combobox") == 0) {
widget = new ComboBox();
}
/* entry */
else if (ustrcmp(elem_name, "entry") == 0) {
const char *maxsize = elem->Attribute("maxsize");
const char *text = elem->Attribute("text");
if (maxsize != NULL) {
bool readonly = bool_attr_is_true(elem, "readonly");
widget = new Entry(ustrtol(maxsize, NULL, 10),
text ? TRANSLATE_ATTR(text): NULL);
if (readonly)
((Entry*)widget)->setReadOnly(true);
}
}
/* grid */
else if (ustrcmp(elem_name, "grid") == 0) {
const char *columns = elem->Attribute("columns");
bool same_width_columns = bool_attr_is_true(elem, "same_width_columns");
if (columns != NULL) {
widget = new Grid(ustrtol(columns, NULL, 10),
same_width_columns);
}
}
/* label */
else if (ustrcmp(elem_name, "label") == 0) {
const char *text = elem->Attribute("text");
widget = new Label(text ? TRANSLATE_ATTR(text): NULL);
if (widget) {
bool center = bool_attr_is_true(elem, "center");
bool right = bool_attr_is_true(elem, "right");
bool top = bool_attr_is_true(elem, "top");
bool bottom = bool_attr_is_true(elem, "bottom");
widget->setAlign((center ? JI_CENTER:
(right ? JI_RIGHT: JI_LEFT)) |
(top ? JI_TOP:
(bottom ? JI_BOTTOM: JI_MIDDLE)));
}
}
/* listbox */
else if (ustrcmp(elem_name, "listbox") == 0) {
widget = new ListBox();
}
/* listitem */
else if (ustrcmp(elem_name, "listitem") == 0) {
const char *text = elem->Attribute("text");
widget = new ListBox::Item(text ? TRANSLATE_ATTR(text): NULL);
}
/* splitter */
else if (ustrcmp(elem_name, "splitter") == 0) {
示例7:
const std::vector<Field*> Sudoku::getGridElements(const Field* refField) const
{
Grid* grid = (Grid*) refField->belongsTo;
return grid->getGridElements();
}
示例8: if
void TimestepSchemeStrang::Step(
bool fFirstStep,
bool fLastStep,
const Time & time,
double dDeltaT
) {
// Get a copy of the grid
Grid * pGrid = m_model.GetGrid();
// Get a copy of the HorizontalDynamics
HorizontalDynamics * pHorizontalDynamics =
m_model.GetHorizontalDynamics();
// Get a copy of the VerticalDynamics
VerticalDynamics * pVerticalDynamics =
m_model.GetVerticalDynamics();
// Half a time step
double dHalfDeltaT = 0.5 * dDeltaT;
// Vertical timestep
if (fFirstStep) {
pVerticalDynamics->StepImplicit(0, 0, time, dHalfDeltaT);
} else {
pGrid->LinearCombineData(m_dCarryoverCombination, 0, DataType_State);
}
// Forward Euler
if (m_eExplicitDiscretization == ForwardEuler) {
pGrid->CopyData(0, 4, DataType_State);
pHorizontalDynamics->StepExplicit(0, 4, time, dDeltaT);
pVerticalDynamics->StepExplicit(0, 4, time, dDeltaT);
pGrid->PostProcessSubstage(4, DataType_State);
pGrid->PostProcessSubstage(4, DataType_Tracers);
// Explicit fourth-order Runge-Kutta
} else if (m_eExplicitDiscretization == RungeKutta4) {
pGrid->CopyData(0, 1, DataType_State);
pHorizontalDynamics->StepExplicit(0, 1, time, dHalfDeltaT);
pVerticalDynamics->StepExplicit(0, 1, time, dHalfDeltaT);
pGrid->PostProcessSubstage(1, DataType_State);
pGrid->PostProcessSubstage(1, DataType_Tracers);
pGrid->CopyData(0, 2, DataType_State);
pHorizontalDynamics->StepExplicit(1, 2, time, dHalfDeltaT);
pVerticalDynamics->StepExplicit(1, 2, time, dHalfDeltaT);
pGrid->PostProcessSubstage(2, DataType_State);
pGrid->PostProcessSubstage(2, DataType_Tracers);
pGrid->CopyData(0, 3, DataType_State);
pHorizontalDynamics->StepExplicit(2, 3, time, dDeltaT);
pVerticalDynamics->StepExplicit(2, 3, time, dDeltaT);
pGrid->PostProcessSubstage(3, DataType_State);
pGrid->PostProcessSubstage(3, DataType_Tracers);
pGrid->LinearCombineData(m_dRK4Combination, 4, DataType_State);
pHorizontalDynamics->StepExplicit(3, 4, time, dDeltaT / 6.0);
pVerticalDynamics->StepExplicit(3, 4, time, dDeltaT / 6.0);
pGrid->PostProcessSubstage(4, DataType_State);
pGrid->PostProcessSubstage(4, DataType_Tracers);
// Explicit strong stability preserving third-order Runge-Kutta
} else if (m_eExplicitDiscretization == RungeKuttaSSP3) {
pGrid->CopyData(0, 1, DataType_State);
pHorizontalDynamics->StepExplicit(0, 1, time, dDeltaT);
pVerticalDynamics->StepExplicit(0, 1, time, dDeltaT);
pGrid->PostProcessSubstage(1, DataType_State);
pGrid->PostProcessSubstage(1, DataType_Tracers);
pGrid->LinearCombineData(m_dSSPRK3CombinationA, 2, DataType_State);
pHorizontalDynamics->StepExplicit(1, 2, time, 0.25 * dDeltaT);
pVerticalDynamics->StepExplicit(1, 2, time, 0.25 * dDeltaT);
pGrid->PostProcessSubstage(2, DataType_State);
pGrid->PostProcessSubstage(2, DataType_Tracers);
pGrid->LinearCombineData(m_dSSPRK3CombinationB, 4, DataType_State);
pHorizontalDynamics->StepExplicit(2, 4, time, (2.0/3.0) * dDeltaT);
pVerticalDynamics->StepExplicit(2, 4, time, (2.0/3.0) * dDeltaT);
pGrid->PostProcessSubstage(4, DataType_State);
pGrid->PostProcessSubstage(4, DataType_Tracers);
// Explicit Kinnmark, Gray and Ullrich third-order five-stage Runge-Kutta
} else if (m_eExplicitDiscretization == KinnmarkGrayUllrich35) {
pGrid->CopyData(0, 1, DataType_State);
pHorizontalDynamics->StepExplicit(0, 1, time, dDeltaT / 5.0);
pVerticalDynamics->StepExplicit(0, 1, time, dDeltaT / 5.0);
pGrid->PostProcessSubstage(1, DataType_State);
pGrid->PostProcessSubstage(1, DataType_Tracers);
pGrid->CopyData(0, 2, DataType_State);
pHorizontalDynamics->StepExplicit(1, 2, time, dDeltaT / 5.0);
pVerticalDynamics->StepExplicit(1, 2, time, dDeltaT / 5.0);
pGrid->PostProcessSubstage(2, DataType_State);
pGrid->PostProcessSubstage(2, DataType_Tracers);
pGrid->CopyData(0, 3, DataType_State);
//.........这里部分代码省略.........
示例9: main
/**
* hex-constraints.exe [TreeSearch arguments] --rules [file]
*
* Load the rules from the given file (possibly with values?) and use that to generate
* all of the constraints for the linear program.
*/
int main(int argc, char** argv)
{
// TODO: Make grid and conf be changeable by arguments?
int grid_type = HEXAGONAL_GRID;
bool blowup = false; // do blowup?
bool tblowup = false; // do tight blowup?
bool tbt = false;
bool tt = false;
bool ttt = false;
bool dual = false; // do dual? (after blowup, maybe?)
int mode = MODE_IDENTIFYING;
for ( int i = 1; i < argc; i++ )
{
if ( strcmp(argv[i],"--hexagonal")== 0)
{
grid_type = HEXAGONAL_GRID;
}
if ( strcmp(argv[i],"--hexnorot")== 0)
{
grid_type = HEXAGONAL_GRID_NO_ROTATE;
}
if ( strcmp(argv[i],"--square")== 0)
{
grid_type = SQUARE_GRID;
}if ( strcmp(argv[i],"--triangular")== 0)
{
grid_type = TRIANGULAR_GRID;
}
if ( strcmp(argv[i],"--identifying")== 0)
{
mode = MODE_IDENTIFYING;
}
if ( strcmp(argv[i],"--dominating")== 0)
{
mode = MODE_DOMINATING;
}
if ( strcmp(argv[i],"--locating")== 0)
{
mode = MODE_LOCATING_DOMINATING;
}
if ( strcmp(argv[i],"--strongidentifying")== 0)
{
mode = MODE_STRONG_IDENTIFYING;
}
if ( strcmp(argv[i],"--openneighborhood")== 0)
{
mode = MODE_OPEN_NEIGHBORHOOD;
}
if ( strcmp(argv[i],"--neighbor")== 0)
{
mode = MODE_NEIGHBOR_IDENTIFYING;
}
if ( strcmp(argv[i],"--tblowup")== 0)
{
tblowup = true;
}
if ( strcmp(argv[i],"--blowup")== 0)
{
blowup = true;
}
if ( strcmp(argv[i],"--dual")== 0)
{
dual = true;
}
if ( strcmp(argv[i],"--tdt")== 0)
{
tbt = true;
}
if ( strcmp(argv[i],"--tt")== 0)
{
tt = true;
}
if ( strcmp(argv[i],"--ttt")== 0)
{
ttt = true;
}
}
Grid* grid = 0;
switch ( grid_type )
{
case HEXAGONAL_GRID:
grid = new HexagonalGrid(12);
break;
case HEXAGONAL_GRID_NO_ROTATE:
grid = new HexagonalGridNoRotate(12);
break;
case SQUARE_GRID:
grid = new SquareGrid(12);
//.........这里部分代码省略.........
示例10: BOOST_FIXTURE_TEST_CASE
BOOST_FIXTURE_TEST_CASE(ExposedModelGUITestCase, ExposedModelFixture)
{
model::Viewer viewer;
viewer.height = 500;
viewer.width = 500;
model.addElement("viewer", viewer);
model.addElement<bool>("myTab", false);
model.addElement<bool>("myBool", false);
model.addElement<std::string>("myVal", "THIS WORKS!");
const char* restrictions[] = {"select1", "select2", "select3", "select4"};
model.addElementWithRestriction<std::string>("myVal2", "select1",
&restrictions[0], &restrictions[4]);
model.addConstrainedElement<int>("myIntBA", 5,0, 900);
model.addConstrainedElement<double>("myDouble", 10., 0., 11.);
model.addElement<bool>("myButton", false);
using namespace model::gui;
TabLayout* root = new TabLayout();
HorizontalLayout *superLayout = new HorizontalLayout();
Grid *mainGrid = new Grid(10, 1);
superLayout->addChild(mainGrid);
Tab *mainTab = new Tab("myTab");
mainTab->setChild(superLayout);
root->addChild(mainTab);
// Used to hold our two input fields.
// Simple Label-input-layout
Grid *input1Grid = new Grid(3,2);
mainGrid->setChild(0,0, input1Grid);
input1Grid->setChild(0, 0, new Label("myVal"));
input1Grid->setChild(0, 1, new TextInput("myVal"));
input1Grid->setChild(1,0, new Label("myVal2"));
input1Grid->setChild(1,1, new ComboBox("myVal2"));
input1Grid->setChild(2,0, new Label("myVal2"));
input1Grid->setChild(2,1, new RadioButtons("myVal2"));
mainGrid->setChild(1, 0, new SpinBox("myIntBA"));
mainGrid->setChild(2, 0, new TextInput("myIntBA"));
mainGrid->setChild(3, 0, new CheckBox("myTab"));
mainGrid->setChild(4, 0, new CheckBox("myTab"));
mainGrid->setChild(5, 0, new Button("myButton"));
mainGrid->setChild(6, 0, new HorizontalSlider("myIntBA"));
mainGrid->setChild(8,0, new DoubleSpinBox("myDouble"));
mainGrid->setChild(9, 0, new CheckBox("myBool"));
ElementGroup* elemGroup = new ElementGroup("myTab", false);
elemGroup->setChild(new TextInput("myVal"));
mainGrid->setChild(7, 0, elemGroup);
Grid* canvasGrid = new Grid(2,1);
Canvas *canvas = new Canvas("viewer");
canvasGrid->setChild(0,0, canvas);
VerticalLayout* verticalLayout = new VerticalLayout;
verticalLayout->setVisibilityKey( "myBool" );
canvasGrid->setChild(1,0, verticalLayout);
superLayout->addChild(canvasGrid);
model.setGUILayout(root, DESKTOP);
std::vector<model::StateSchemaElement> elements;
model.getFullStateSchema(elements);
}
示例11: T
void TestCholeskyMod
( bool testCorrectness, bool print, UpperOrLower uplo, Int m, Int n,
Base<F> alpha, const Grid& g )
{
DistMatrix<F> T(g), A(g);
HermitianUniformSpectrum( T, m, 1e-9, 10 );
if( testCorrectness )
{
if( g.Rank() == 0 )
{
cout << " Making copy of original matrix...";
cout.flush();
}
A = T;
if( g.Rank() == 0 )
cout << "DONE" << endl;
}
if( print )
Print( T, "A" );
if( g.Rank() == 0 )
{
cout << " Starting Cholesky factorization...";
cout.flush();
}
double startTime = mpi::Time();
Cholesky( uplo, T );
double runTime = mpi::Time() - startTime;
double realGFlops = 1./3.*Pow(double(m),3.)/(1.e9*runTime);
double gFlops = ( IsComplex<F>::val ? 4*realGFlops : realGFlops );
if( g.Rank() == 0 )
{
cout << "DONE\n"
<< " Time = " << runTime << " seconds. GFlops = "
<< gFlops << endl;
}
MakeTrapezoidal( uplo, T );
if( print )
Print( T, "Cholesky factor" );
if( g.Rank() == 0 )
{
cout << " Generating random update vectors...";
cout.flush();
}
DistMatrix<F> V(g), VMod(g);
Uniform( V, m, n );
Scale( F(1)/Sqrt(F(m)*F(n)), V );
VMod = V;
if( g.Rank() == 0 )
cout << "DONE" << endl;
if( print )
Print( V, "V" );
if( g.Rank() == 0 )
{
cout << " Starting Cholesky modification...";
cout.flush();
}
startTime = mpi::Time();
CholeskyMod( uplo, T, alpha, VMod );
runTime = mpi::Time() - startTime;
if( g.Rank() == 0 )
cout << "DONE\n"
<< " Time = " << runTime << " seconds." << endl;
if( print )
Print( T, "Modified Cholesky factor" );
if( testCorrectness )
TestCorrectness( uplo, T, alpha, V, A );
}
示例12: dump_grid
void dump_grid(const Grid & grid, FILE * stream)
{
dump_grid_range(grid, grid.GetXBegin(), grid.GetYBegin(),
grid.GetXEnd() - 1, grid.GetYEnd() - 1,
stream);
}
示例13: createSolidMaze
void createSolidMaze(Grid& maze, int row, int column)
{
SFCOORD curTile = { column, row };
stack<SFCOORD> tileList;
tileList.push(curTile);
while (!tileList.empty())
{
vector<int> moves;
neighborsSF(maze, curTile, moves);
if (!moves.empty())
{
SFCOORD temp;
switch (moves[0])
{
case 1: // Down
temp.x = curTile.x;
temp.y = curTile.y - 2;
maze.getTile(curTile.y - 1, curTile.x)->setWall(false);
maze.getTile(curTile.y - 2, curTile.x)->setWall(false);
//cout << maze.getTile(row - 1, column)->isWall();
//cout << maze.getTile(row - 2, column)->isWall();
curTile = temp;
tileList.push(curTile);
break;
case 2: // Up
temp.x = curTile.x;
temp.y = curTile.y + 2;
maze.getTile(curTile.y + 1, curTile.x)->setWall(false);
maze.getTile(curTile.y + 2, curTile.x)->setWall(false);
curTile = temp;
tileList.push(curTile);
break;
case 3: // Left
temp.x = curTile.x - 2;
temp.y = curTile.y;
maze.getTile(curTile.y, curTile.x - 1)->setWall(false);
maze.getTile(curTile.y, curTile.x - 2)->setWall(false);
curTile = temp;
tileList.push(curTile);
break;
case 4: // Right
temp.x = curTile.x + 2;
temp.y = curTile.y;
maze.getTile(curTile.y, curTile.x + 1)->setWall(false);
maze.getTile(curTile.y, curTile.x + 2)->setWall(false);
curTile = temp;
tileList.push(curTile);
break;
}
}
else
{
curTile = tileList.top();
tileList.pop();
}
}
}
示例14: ToGrid
void MyStrategy::move(const Car& self, const World& world, const Game& game, Move& move) {
if (!inited) {
inited = true;
gr = ToGrid(world.getTilesXY());
gr = gr.Transposed();
::grid << gr;
for (auto& w : world.getWaypoints()) {
tiles << "col: " << w[0] << " row: " << w[1] << endl;
waypoints.emplace_back(w[1], w[0]);
}
auto is_neighbor = [&](const Position& p, grid::Direction d) {
return neighbors[static_cast<int>(gr[p])][d];
};
// shouldn't use grid at all here... or push values inside is_neighbor
// but there maybe some cool logic
BFS<TileType, decltype(is_neighbor)> bfs;
bfs.Init(gr, is_neighbor);
bfs.FindShortestPaths({14,2}, {13,13});
for (int i = 0; i < world.getWaypoints().size(); ++i) {
int i_next = (i+1) % world.getWaypoints().size();
auto res = bfs.FindShortestPaths(waypoints[i], waypoints[i_next]);
ways << waypoints[i] << "; " << waypoints[i_next] << endl;
for (auto r : res) {
for (auto p : r) {
ways << p << "; ";
}
ways << endl;
}
ways << endl;
}
}
Position next_tile{self.getNextWaypointY(), self.getNextWaypointX()};
Point target;
target.x = (next_tile.col + 0.5) * game.getTrackTileSize();
target.y = (next_tile.row + 0.5) * game.getTrackTileSize();
// if (next_tile.ManhattanDistance(currentTile(self)) <= 2) {
switch (world.getTilesXY()[next_tile.col][next_tile.row]) {
case LEFT_TOP_CORNER:
target.x += game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3;
target.y += game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3;
// nextWaypointX += cornerTileOffset;
// nextWaypointY += cornerTileOffset;
break;
case RIGHT_TOP_CORNER:
target.x -= (game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3);
target.y += game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3;
// nextWaypointX -= cornerTileOffset;
// nextWaypointY += cornerTileOffset;
break;
case LEFT_BOTTOM_CORNER:
target.x += game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3;
target.y -= (game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3);
// nextWaypointX += cornerTileOffset;
// nextWaypointY -= cornerTileOffset;
break;
case RIGHT_BOTTOM_CORNER:
target.x -= (game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3);
target.y -= (game.getTrackTileSize()/2 - game.getTrackTileMargin() - self.getWidth()/3);
// nextWaypointX -= cornerTileOffset;
// nextWaypointY -= cornerTileOffset;
break;
case RIGHT_HEADED_T:
break;
case LEFT_HEADED_T:
break;
case TOP_HEADED_T:
break;
case BOTTOM_HEADED_T:
break;
case CROSSROADS:
break;
default:
break;
}
// }
double angleToWaypoint = self.getAngleTo(target.x, target.y);
double speedModule = hypot(self.getSpeedX(), self.getSpeedY());
move.setWheelTurn(angleToWaypoint * 100. / PI);
move.setEnginePower(1.);
if (speedModule != prevSpeed) {
stats << speedModule << endl;
}
prevSpeed = speedModule;
//.........这里部分代码省略.........
示例15: Compute
void GaussSeidelRB::Compute(Grid& sol, Grid& rhs)
{
const Stencil& mat = MG::GetDiscretization()->GetStencil();
const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol);
const vmg_float diag_inv = 1.0 / mat.GetDiag();
const int off = rhs.Global().LocalBegin().Sum() - rhs.Local().HaloSize1().Sum();
const LocalIndices& local = rhs.Local();
Comm& comm = *MG::GetComm();
/*
* Compute first halfstep
*/
// Start asynchronous communication
comm.CommToGhostsAsyncStart(sol);
// Smooth part not depending on ghost cells
ComputePartial(sol, rhs, mat,
local.Begin()+1, local.End()-1,
prefactor_inv, diag_inv, off+1);
// Finish asynchronous communication
comm.CommToGhostsAsyncFinish(sol);
/*
* Smooth near boundary cells
*/
ComputePartial(sol, rhs, mat,
local.Begin(),
Index(local.Begin().X()+1, local.End().Y(), local.End().Z()),
prefactor_inv, diag_inv, off+1);
ComputePartial(sol, rhs, mat,
Index(local.End().X()-1, local.Begin().Y(), local.Begin().Z()),
local.End(),
prefactor_inv, diag_inv, off+1);
ComputePartial(sol, rhs, mat,
Index(local.Begin().X()+1, local.Begin().Y(), local.Begin().Z()),
Index(local.End().X()-1, local.Begin().Y()+1, local.End().Z()),
prefactor_inv, diag_inv, off+1);
ComputePartial(sol, rhs, mat,
Index(local.Begin().X()+1, local.End().Y()-1, local.Begin().Z()),
Index(local.End().X()-1, local.End().Y(), local.End().Z()),
prefactor_inv, diag_inv, off+1);
ComputePartial(sol, rhs, mat,
Index(local.Begin().X()+1, local.Begin().Y()+1, local.Begin().Z()),
Index(local.End().X()-1, local.End().Y()-1, local.Begin().Z()+1),
prefactor_inv, diag_inv, off+1);
ComputePartial(sol, rhs, mat,
Index(local.Begin().X()+1, local.Begin().Y()+1, local.End().Z()-1),
Index(local.End().X()-1, local.End().Y()-1, local.End().Z()),
prefactor_inv, diag_inv, off+1);
/*
* Compute second halfstep
*/
// Start asynchronous communication
comm.CommToGhostsAsyncStart(sol);
// Smooth part not depending on ghost cells
ComputePartial(sol, rhs, mat,
local.Begin()+1, local.End()-1,
prefactor_inv, diag_inv, off);
// Finish asynchronous communication
comm.CommToGhostsAsyncFinish(sol);
/*
* Smooth near boundary cells
*/
ComputePartial(sol, rhs, mat,
local.Begin(),
Index(local.Begin().X()+1, local.End().Y(), local.End().Z()),
prefactor_inv, diag_inv, off);
ComputePartial(sol, rhs, mat,
Index(local.End().X()-1, local.Begin().Y(), local.Begin().Z()),
local.End(),
prefactor_inv, diag_inv, off);
ComputePartial(sol, rhs, mat,
Index(local.Begin().X()+1, local.Begin().Y(), local.Begin().Z()),
Index(local.End().X()-1, local.Begin().Y()+1, local.End().Z()),
prefactor_inv, diag_inv, off);
ComputePartial(sol, rhs, mat,
Index(local.Begin().X()+1, local.End().Y()-1, local.Begin().Z()),
Index(local.End().X()-1, local.End().Y(), local.End().Z()),
prefactor_inv, diag_inv, off);
ComputePartial(sol, rhs, mat,
Index(local.Begin().X()+1, local.Begin().Y()+1, local.Begin().Z()),
Index(local.End().X()-1, local.End().Y()-1, local.Begin().Z()+1),
//.........这里部分代码省略.........