Esempio n. 1
0
/*Purpose:Intiates a buffer Pool with specific properties*/
RC initBufferPool(BM_BufferPool *const bm, const char *const pageFileName, const int numPages, ReplacementStrategy strategy,void *stratData)
{
SM_FileHandle fh;
int i=0,flag=1;

if(openPageFile((char *)pageFileName,&fh)==RC_OK)
{
 
    BufferManager *bfmanger=malloc(sizeof(BufferManager));
    bfmanger->Total_ReadIO=0;
    bfmanger->Total_WriteIO=0;
    bfmanger->frameCount=numPages;
    bfmanger->strategy=strategy;
    memset(bfmanger->DirtyValue,false,MAX_FRAMES*sizeof(bool));
    memset(bfmanger->PagesFixedCount,0,MAX_FRAMES*sizeof(int));
    memset(bfmanger->Map_Frame_To_Page,NO_PAGE,MAX_FRAMES*sizeof(int));
    memset(bfmanger->Map_Page_To_Frame,NO_PAGE,MAX_PAGE_SIZE_1*sizeof(int));
    bm->strategy=strategy;
    bm->numPages=numPages;
    bfmanger->PageFileName=(char *)pageFileName;
    for( i=0;i<numPages;i++) /*Creates a Doubly Linked List*/
    {
        if(flag==1)
        {
      
            bfmanger->LastNode=bfmanger->HeadNode=CreateNodes();
            flag=0;
            bfmanger->HeadNode->previous=NULL;
            bfmanger->LastNode->next=NULL;
        }
        else
        {
    
            bfmanger->LastNode->next=CreateNodes();
            bfmanger->LastNode->next->previous=bfmanger->LastNode;
            bfmanger->LastNode=bfmanger->LastNode->next;
            bfmanger->LastNode->next=NULL;
        }
        bfmanger->LastNode->FrameNumber=i;
        bfmanger->LastNode->FrameNum=i;
    }
    bfmanger->fileHandler_StorageMgr=fh;
    bfmanger->Frame_List_Value=CreateFrameList_forLRU(numPages);
    bm->mgmtData=bfmanger;
    
return RC_OK;
}
    
RC_message = "initBufferPool";
return RC_FILE_NOT_FOUND;			  
}
Esempio n. 2
0
static void Read_EDGE_WEIGHT_SECTION()
{
    Node *Ni, *Nj;
    int i, j, n, W;

    if (!FirstNode)
        CreateNodes();
	n = Dimension / 2;
	assert(CostMatrix = (int *) calloc((size_t) n * n, sizeof(int)));//sizeof(size_t)=8,分配n * n个int
	for (Ni = FirstNode; Ni->Id <= n; Ni = Ni->Suc)
		Ni->C = &CostMatrix[(size_t) (Ni->Id - 1) * n] - 1;
            
	n = Dimension / 2;
	for (i = 1; i <= n; i++)
	{
		Ni = &NodeSet[i];
		for (j = 1; j <= n; j++) 
		{
			W = Rp0->VVcost[i-1][j-1];/****************my data**********/
			Ni->C[j] = W;
			if (i != j && W > M)
				M = W;
		}
		Nj = &NodeSet[i + n];
		if (!Ni->FixedTo1)
			Ni->FixedTo1 = Nj;
		if (!Nj->FixedTo1)
			Nj->FixedTo1 = Ni;
	}
}
Esempio n. 3
0
void InputTreeBuilder::Build(const TreeInput &in,
                             const std::string &topLevelLabel,
                             InputTree &out)
{
  CreateNodes(in, topLevelLabel, out);
  ConnectNodes(out);
}
Esempio n. 4
0
//! Construct a simple torus graph
void constructTorus(Graph& g, int height, int width) {
  // Construct set of nodes
  int numNodes = height * width;
  std::vector<Point2D> points(numNodes);
  for (int x = 0; x < width; ++x) {
    for (int y = 0; y < height; ++y) {
      points[x*height + y] = Point2D(x, y);
    }
  }
  // Sort in a space-filling way
  std::sort(points.begin(), points.end(), ZOrderCompare());

  // Using space-filling order, assign nodes and create (and allocate) them in parallel
  std::vector<GNode> nodes(numNodes);
  Galois::do_all(points.begin(), points.end(), CreateNodes(g, nodes, height));

  // Add edges
  for (int x = 0; x < width; ++x) {
    for (int y = 0; y < height; ++y) {
      GNode c = nodes[x*height + y];
      GNode n = nodes[x*height + ((y+1) % height)];
      GNode s = nodes[x*height + ((y-1+height) % height)];
      GNode e = nodes[((x+1) % width)*height + y];
      GNode w = nodes[((x-1+width) % width)*height + y];
      g.addEdge(c, n);
      g.addEdge(c, s);
      g.addEdge(c, e);
      g.addEdge(c, w);
    }
  }
}
Esempio n. 5
0
//
//--- Create the nodes.
//
void CAStar::CreateNodes(int in_x, int in_y, int in_size)
{
	//--- Check is there is something in the way
	int x,y;
	unsigned char value;
	for (y=in_y;y<in_y+in_size;++y)
	{
		for (x=in_x;x<in_x+in_size;++x)
		{
			//--- We have to be sure it's all the same value
			if (y == in_y && x == in_x) 
			{
				value = m_mapArray[(y * m_sizeX) + x];
			}
			else if (m_mapArray[(y * m_sizeX) + x] != value)
			{
				//--- Split it
				CreateNodes(in_x, in_y, in_size / 2);
				CreateNodes(in_x, in_y + in_size / 2, in_size / 2);
				CreateNodes(in_x + in_size / 2, in_y + in_size / 2, in_size / 2);
				CreateNodes(in_x + in_size / 2, in_y, in_size / 2);
				return;
			}
		}
	}

	//--- If we didn't stop, we have our node!
	CPathNode *newNode = new CPathNode();
	newNode->m_x = in_x;
	newNode->m_y = in_y;
	newNode->m_sizeX = in_size;
	newNode->m_sizeY = in_size;
	newNode->m_value = value;
	newNode->m_centerX = (float)in_x + (float)in_size * .5f;
	newNode->m_centerY = (float)in_y + (float)in_size * .5f;
	ASTAR_PUSH_BACK(m_lstNodes, newNode);

	//--- Fill the m_mapNodesRef
	for (y=in_y;y<in_y+in_size;++y)
	{
		for (x=in_x;x<in_x+in_size;++x)
		{
			m_mapNodesRef[(y * m_sizeX) + x] = newNode;
		}
	}
}
Esempio n. 6
0
/**
 * Create the globe's geometry and nodes.
 *
 * \param iTriangleCount The desired triangle count of the entire globe.  The
 *		class will attempt to match this value as closely as possible with
 *		the indicated tessellation.
 * \param strImagePrefix The base of the filename for the set of icosahedral
 *		surface textures.  For example, if your textures have the name
 *		"geosphere_*.jpg", pass "geosphere_"
 * \param style Tessellation style, can be one of:
 *		- GEODESIC	A classic geodesic tiling based on subdividing the edges
 *			of the icosahedron and gnomonically projecting them to the sphere.
 *		- RIGHT_TRIANGLE	An alternative approach where each face is
 *			divided into right triangles recursively.
 *		- DYMAX_UNFOLD	Same as RIGHT_TRIANGLE but the faces are also placed
 *			on seperate geometries so that the globe can be unfolded in the
 *			Dymaxion style.
 */
void vtIcoGlobe::Create(int iTriangleCount, const vtString &strImagePrefix, Style style)
{
    VTLOG("vtIcoGlobe::Create\n");

    m_style = style;
    CreateMeshMat(iTriangleCount);
    CreateCoreMaterials();
    SetEarthMaterials(CreateMaterialsFromFiles(strImagePrefix));
    CreateNodes();
}
Esempio n. 7
0
void vtIcoGlobe::Create(int iTriangleCount, vtImage **images, Style style)
{
    VTLOG("vtIcoGlobe::Create\n");

    m_style = style;
    CreateMeshMat(iTriangleCount);
    CreateCoreMaterials();
    SetEarthMaterials(CreateMaterialsFromImages(images));
    CreateNodes();
}
Esempio n. 8
0
static void Read_FIXED_EDGES_SECTION()
{
    Node *Ni, *Nj, *N, *NPrev = 0, *NNext;
    int i, j, Count = 0;

    CheckSpecificationPart();
    if (!FirstNode)
        CreateNodes();
    if (ProblemType == HPP)
        Dimension--;
    if (!fscanint(ProblemFile, &i))
        i = -1;
    while (i != -1) {
        if (i <= 0
            || i > (ProblemType != ATSP ? Dimension : Dimension / 2))
            eprintf("(FIXED_EDGES_SECTION) Node number out of range: %d",
                    i);
        fscanint(ProblemFile, &j);
        if (j <= 0
            || j > (ProblemType != ATSP ? Dimension : Dimension / 2))
            eprintf("(FIXED_EDGES_SECTION) Node number out of range: %d",
                    j);
        if (i == j)
            eprintf("(FIXED_EDGES_SECTION) Illegal edge: %d to %d", i, j);
        Ni = &NodeSet[i];
        Nj = &NodeSet[ProblemType == ATSP ? j + Dimension / 2 : j];
        if (!Ni->FixedTo1 || Ni->FixedTo1 == Nj)
            Ni->FixedTo1 = Nj;
        else if (!Ni->FixedTo2 || Ni->FixedTo2 == Nj)
            Ni->FixedTo2 = Nj;
        else
            eprintf("(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
        if (!Nj->FixedTo1 || Nj->FixedTo1 == Ni)
            Nj->FixedTo1 = Ni;
        else if (!Nj->FixedTo2 || Nj->FixedTo2 == Ni)
            Nj->FixedTo2 = Ni;
        else
            eprintf("(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
        /* Cycle check */
        N = Ni;
        Count = 0;
        do {
            NNext = N->FixedTo1 != NPrev ? N->FixedTo1 : N->FixedTo2;
            NPrev = N;
            Count++;
        } while ((N = NNext) && N != Ni);
        if (N == Ni && Count != Dimension)
            eprintf("(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
        if (!fscanint(ProblemFile, &i))
            i = -1;
    }
    if (ProblemType == HPP)
        Dimension++;
}
Esempio n. 9
0
static void Read_NODE_COORD_SECTION()
{
    Node *N;
    int Id, i;

    CheckSpecificationPart();
    if (CoordType != TWOD_COORDS && CoordType != THREED_COORDS)
        eprintf("NODE_COORD_SECTION conflicts with NODE_COORD_TYPE: %s",
                NodeCoordType);
    if (!FirstNode)
        CreateNodes();
    N = FirstNode;
    do
        N->V = 0;
    while ((N = N->Suc) != FirstNode);
    if (ProblemType == HPP)
        Dimension--;
    for (i = 1; i <= Dimension; i++) {
        if (!fscanint(ProblemFile, &Id))
            eprintf("Missing nodes in NODE_COORD_SECTION");
        if (Id <= 0 || Id > Dimension)
            eprintf("(NODE_COORD_SECTION) Node number out of range: %d",
                    Id);
        N = &NodeSet[Id];
        if (N->V == 1)
            eprintf("(NODE_COORD_SECTION) Node number occurs twice: %d",
                    N->Id);
        N->V = 1;
        if (!fscanf(ProblemFile, "%lf", &N->X))
            eprintf("Missing X-coordinate in NODE_COORD_SECTION");
        if (!fscanf(ProblemFile, "%lf", &N->Y))
            eprintf("Missing Y-coordinate in NODE_COORD_SECTION");
        if (CoordType == THREED_COORDS
            && !fscanf(ProblemFile, "%lf", &N->Z))
            eprintf("Missing Z-coordinate in NODE_COORD_SECTION");
        if (Name && !strcmp(Name, "d657")) {
            N->X = (float) N->X;
            N->Y = (float) N->Y;
        }
    }
    N = FirstNode;
    do
        if (!N->V && N->Id <= Dimension)
            break;
    while ((N = N->Suc) != FirstNode);
    if (!N->V)
        eprintf("(NODE_COORD_SECTION) No coordinates given for node %d",
                N->Id);
    if (ProblemType == HPP)
        Dimension++;
}
TurretManager::TurretManager()
{
	//orbit01Angle = 0.0f;
	orbit02Angle = 0.0f;
	turret01Sprite = new uth::Sprite("CannonTower.png");
	turret01Texture = uthRS.LoadTexture("pixelTurrets.png");
	bulletTexture = uthRS.LoadTexture("projectileSheet.png");
	node01Texture = uthRS.LoadTexture("buttonTest.png");
	towerButtonTexture = uthRS.LoadTexture("particle.png");
	disruptorProjectile = uthRS.LoadTexture("Projectile_Disruptor.png");
	
	RocketButton = uthRS.LoadTexture("RocketButton.png");
	RailgunButton = uthRS.LoadTexture("RailgunButton.png");
	DisruptorButton = uthRS.LoadTexture("disruptorButton.png");
	CannonButton = uthRS.LoadTexture("CannonButton.png");
	BeamButton = uthRS.LoadTexture("BeamButton.png");
	GatlingLaserButton = uthRS.LoadTexture("GatlingLaserButton.png");
	CancelButton = uthRS.LoadTexture("CancelButton.png");

	CreateNodes();

	towers[0] = new ns::Button(uthEngine.GetWindow(), CannonButton);
	towers[1] = new ns::Button(uthEngine.GetWindow(), GatlingLaserButton);
	towers[2] = new ns::Button(uthEngine.GetWindow(), BeamButton);
	towers[3] = new ns::Button(uthEngine.GetWindow(), RocketButton);
	towers[4] = new ns::Button(uthEngine.GetWindow(), DisruptorButton);
	towers[5] = new ns::Button(uthEngine.GetWindow(), RailgunButton);
	
	for (size_t i = 0; i < 6; i++)
	{
		towers[i]->transform.SetScale(0.6f);
		towerButtons.emplace_back(towers[i]);
		AddChild(towerButtons.back());
		towers[i]->SetActive(false);
		towers[i]->AddTag("Tower");
	}

	cancel = new ns::Button(uthEngine.GetWindow(), CancelButton);
	AddChild(cancel);
	cancel->SetActive(false);
	cancel->AddTag("Cancel");
	cancel->transform.SetScale(0.6f);

	cancel->setCallBack([&]()
	{
		poisto();
	});

	UI = false;
}
void
HwmpReactiveRegressionTest::DoRun ()
{
  RngSeedManager::SetSeed (12345);
  RngSeedManager::SetRun (7);
  CreateNodes ();
  CreateDevices ();
  InstallApplications ();

  Simulator::Stop (m_time);
  Simulator::Run ();
  Simulator::Destroy ();

  CheckResults ();
  delete m_nodes, m_nodes = 0;
}
Esempio n. 12
0
static void Read_EDGE_DATA_SECTION()
{
    Node *Ni, *Nj;
    int i, j;

    CheckSpecificationPart();
    if (!EdgeDataFormat)
        eprintf("Missing EDGE_DATA_FORMAT specification");
    if (!FirstNode)
        CreateNodes();
    if (ProblemType == HPP)
        Dimension--;
    if (!fscanint(ProblemFile, &i))
        i = -1;
    while (i != -1) {
        if (i <= 0 ||
            i > (ProblemType != ATSP ? Dimension : Dimension / 2))
            eprintf("(EDGE_DATA_SECTION) Node number out of range: %d", i);
        fscanint(ProblemFile, &j);
        if (j == -1 && !strcmp(EdgeDataFormat, "EDGE_LIST"))
            eprintf("(EDGE_DATA_SECTION) Node number out of range: %d", -1);
        while (j != -1) {
            printff("i = %d, j = %d\n", i, j);
            if (j <= 0 || j > (ProblemType != ATSP ? Dimension : Dimension / 2))
                eprintf("(EDGE_DATA_SECTION) Node number out of range: %d", j);
            if (i == j)
                eprintf("(EDGE_DATA_SECTION) Illegal edge: %d to %d", i, j);
            if (ProblemType == ATSP) {
                i += Dimension / 2;
                j += Dimension / 2;
            }
            Ni = &NodeSet[i];
            Nj = &NodeSet[j];
            AddCandidate(Ni, Nj, 0, 1);
            if (ProblemType != ATSP)
                AddCandidate(Nj, Ni, 0, 1);
            if (!strcmp(EdgeDataFormat, "EDGE_LIST") ||
                !fscanint(ProblemFile, &j))
                j = -1;
        }
        if (!fscanint(ProblemFile, &i))
            i = -1;
    }
    if (ProblemType == HPP)
        Dimension++;
    Distance = Distance_1;
}
Esempio n. 13
0
static void Read_DISPLAY_DATA_SECTION()
{
    Node *N;
    int Id, i;

    CheckSpecificationPart();
    if (ProblemType == HPP)
        Dimension--;
    if (!DisplayDataType || strcmp(DisplayDataType, "TWOD_DISPLAY"))
        eprintf
            ("DISPLAY_DATA_SECTION conflicts with DISPLAY_DATA_TYPE: %s",
             DisplayDataType);
    if (!FirstNode)
        CreateNodes();
    N = FirstNode;
    do
        N->V = 0;
    while ((N = N->Suc) != FirstNode);
    N = FirstNode;
    for (i = 1; i <= Dimension; i++) {
        if (!fscanint(ProblemFile, &Id))
            eprintf("Missing nodes in DIPLAY_DATA_SECTION");
        if (Id <= 0 || Id > Dimension)
            eprintf("(DIPLAY_DATA_SECTION) Node number out of range: %d",
                    Id);
        N = &NodeSet[Id];
        if (N->V == 1)
            eprintf("(DIPLAY_DATA_SECTION) Node number occours twice: %d",
                    N->Id);
        N->V = 1;
        if (!fscanf(ProblemFile, "%lf", &N->X))
            eprintf("Missing X-coordinate in DIPLAY_DATA_SECTION");
        if (!fscanf(ProblemFile, "%lf", &N->Y))
            eprintf("Missing Y-coordinate in DIPLAY_DATA_SECTION");
    }
    N = FirstNode;
    do
        if (!N->V)
            break;
    while ((N = N->Suc) != FirstNode);
    if (!N->V)
        eprintf("(DIPLAY_DATA_SECTION) No coordinates given for node %d",
                N->Id);
    if (ProblemType == HPP)
        Dimension++;
}
Esempio n. 14
0
static void Read_FIXED_EDGES_SECTION()
{
    Node *Ni, *Nj;
    int i, j;
    CheckSpecificationPart();
    if (!FirstNode)
        CreateNodes();
    if (ProblemType == HPP)
        Dimension--;
    if (!fscanint(ProblemFile, &i))
        i = -1;
    while (i != -1) {
        if (i <= 0
            || i > (ProblemType != ATSP ? Dimension : Dimension / 2))
            eprintf("(FIXED_EDGES_SECTION) Node number out of range: %d",
                    i);
        fscanint(ProblemFile, &j);
        if (j <= 0
            || j > (ProblemType != ATSP ? Dimension : Dimension / 2))
            eprintf("(FIXED_EDGES_SECTION) Node number out of range: %d",
                    j);
        if (i == j)
            eprintf("(FIXED_EDGES_SECTION) Illgal edge: %d to %d", i, j);
        if (ProblemType == ATSP)
            i += Dimension / 2;
        Ni = &NodeSet[i];
        Nj = &NodeSet[j];
        if (!Ni->FixedTo1)
            Ni->FixedTo1 = Nj;
        else if (!Ni->FixedTo2)
            Ni->FixedTo2 = Nj;
        else
            eprintf("(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
        if (!Nj->FixedTo1)
            Nj->FixedTo1 = Ni;
        else if (!Nj->FixedTo2)
            Nj->FixedTo2 = Ni;
        else
            eprintf("(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
        if (!fscanint(ProblemFile, &i))
            i = -1;
    }
    if (ProblemType == HPP)
        Dimension++;
}
Esempio n. 15
0
bool Initialize(hPtr& deck, hPtr& player1Hand, hPtr& player2Hand, hPtr& player3Hand, hPtr& player4Hand)
{
	deck->list = CreateNodes(kDeckSize);

	player1Hand->list = (cPtr)malloc(sizeof(_c));
	player1Hand->list->suit = -1;//if Length() is called and it returns 1, this can be used to test if it's 1 actual node, or just the initial allocated node with garbage values
	player1Hand->list->next = NULL;
	player2Hand->list = (cPtr)malloc(sizeof(_c));
	player2Hand->list->suit = -1;//same as above
	player2Hand->list->next = NULL;
	player3Hand->list = (cPtr)malloc(sizeof(_c));
	player3Hand->list->suit = -1;//same as above
	player3Hand->list->next = NULL;
	player4Hand->list = (cPtr)malloc(sizeof(_c));
	player4Hand->list->suit = -1;//same as above
	player4Hand->list->next = NULL;

	ShuffleCards(deck->list);

	DealCards(deck->list, player1Hand->list, kHandSize);
	DealCards(deck->list, player2Hand->list, kHandSize);
	DealCards(deck->list, player3Hand->list, kHandSize);
	DealCards(deck->list, player4Hand->list, kHandSize);

	if(Length(deck->list) == kDeckSize - (4 * kHandSize))
	{
		if(Length(player1Hand->list) == kHandSize)
		{
			if(Length(player2Hand->list) == kHandSize)
			{
				if(Length(player3Hand->list) == kHandSize)
				{
					if(Length(player4Hand->list) == kHandSize)
					{
						return true;
					}
				}
			}
		}
	}

	return false;
}
Esempio n. 16
0
static void init_graph()
{
	Node *Ni, *Nj;
	int i, j, n, W;


	if (!FirstNode)
		CreateNodes();

	n = Dimension / 2;
	assert(CostMatrix = (int *)calloc((size_t)n * n, sizeof(int)));
	for (Ni = FirstNode; Ni->Id <= n; Ni = Ni->Suc)
		Ni->C = &CostMatrix[(size_t)(Ni->Id - 1) * n] - 1;

	n = Dimension / 2;
	for (i = 1; i <= n; i++) {
		Ni = &NodeSet[i];
		for (j = 1; j <= n; j++) {
			W = TSP_DIST[i - 1][j - 1];//
			if (W == 0) W = INFW;//
			Ni->C[j] = W;
			if (i != j && W > M)
				M = W;
		}
		Nj = &NodeSet[i + n];
		if (!Ni->FixedTo1)
			Ni->FixedTo1 = Nj;
		else if (!Ni->FixedTo2)
			Ni->FixedTo2 = Nj;
		if (!Nj->FixedTo1)
			Nj->FixedTo1 = Ni;
		else if (!Nj->FixedTo2)
			Nj->FixedTo2 = Ni;
	}
	Distance = Distance_ATSP;
	WeightType = -1;


}
Esempio n. 17
0
void PathSolver::Resolve(hashCables cables, Renderer *renderer)
{
    Clear();

    if(cables.size()==0) {
        return;
    }

    mutex.lock();

    listCables = cables;

    CreateNodes();
    PutParentsInNodes();
    UnwrapLoops();
    UpdateDelays(myHost,&cables,&listNodes);
    int cpt=0;
    while(ChainNodes() && cpt<100) { ++cpt; }
    RemoveUnusedNodes();
    SetMinAndMaxStep();

    renderer->OnNewRenderingOrder(listNodes);
    mutex.unlock();
}
Esempio n. 18
0
void QuoteGraph::CreateGraph(PNGraph& QGraph) {
  this->QGraph = TNGraph::New();
  CreateNodes();
  CreateEdges();
  QGraph = this->QGraph;
}
Esempio n. 19
0
// I inlined most of ReadProblem in my StEStructTSP code.
// Need to invoke CreateNodes, which is declared static here.
// Also invoke CheckSpecification while I am at it.
void EStructTSP_CreateNodes() {
    CheckSpecificationPart();
    CreateNodes();
}
Esempio n. 20
0
//
//--- To build it.
//
int CAStar::Build(const unsigned char * in_mapArray, 
				  const int in_sizeX, 
				  const int in_sizeY)
{
	//--- We clean to be sure
	Clean();

	//--- Copy the array
	if (!in_mapArray) return 0;
	m_sizeX = in_sizeX;
	m_sizeY = in_sizeY;
	m_mapArray = new unsigned char [m_sizeX * m_sizeY];
	memcpy(m_mapArray, in_mapArray, m_sizeX * m_sizeY);
	m_mapNodesRef = new CPathNode *[m_sizeX * m_sizeY];

	//--- Alright, create the nodes recursively
	int x,y;
	for (y=0;y<m_sizeY;y+=m_maxPathSize)
	{
		for (x=0;x<m_sizeX;x+=m_maxPathSize)
		{
			CreateNodes(x, y, m_maxPathSize);
		}
	}

	//--- Ok, now create the neighborhood list.
	CPathNode* p;
	CPathNode* n;
	int lastSize;
	for (p = m_lstNodes[0]; p; p = p->next)
	{
		//--- Top
		y = p->m_y - 1;
		lastSize = 1;
		for (x = p->m_x - 1; x <= p->m_x + p->m_sizeX; x += 1)
		{
			n = GetNodeAt(x, y);
			if (n)
			{
				lastSize = n->m_sizeX;
				if (p->m_value == n->m_value && !CheckForDiagonalBlocker(p, n)) p->AddNeighbor(n);
			}
			else
			{
				lastSize = 1; // useless
			}
		}

		//--- Down
		y = p->m_y + p->m_sizeY;
		lastSize = 1;
		for (x = p->m_x - 1; x <= p->m_x + p->m_sizeX; x += 1)
		{
			n = GetNodeAt(x, y);
			if (n)
			{
				lastSize = n->m_sizeX;
				if (p->m_value == n->m_value && !CheckForDiagonalBlocker(p, n)) p->AddNeighbor(n);
			}
			else
			{
				lastSize = 1; // useless
			}
		}

		//--- Left
		x = p->m_x - 1;
		lastSize = 1;
		for (y = p->m_y - 1; y <= p->m_y + p->m_sizeY; y += 1)
		{
			n = GetNodeAt(x, y);
			if (n)
			{
				lastSize = n->m_sizeY;
				if (p->m_value == n->m_value && !CheckForDiagonalBlocker(p, n)) p->AddNeighbor(n);
			}
			else
			{
				lastSize = 1; // useless
			}
		}

		//--- Right
		x = p->m_x + p->m_sizeX;
		lastSize = 1;
		for (y = p->m_y - 1; y <= p->m_y + p->m_sizeY; y += 1)
		{
			n = GetNodeAt(x, y);
			if (n)
			{
				lastSize = n->m_sizeY;
				if (p->m_value == n->m_value && !CheckForDiagonalBlocker(p, n)) p->AddNeighbor(n);
			}
			else
			{
				lastSize = 1; // useless
			}
		}
	}
	
	//--- Successful
	return 1;
}
Esempio n. 21
0
static void Read_EDGE_DATA_SECTION()
{
    Node *Ni, *Nj;
    int i, j;

    CheckSpecificationPart();
    if (!EdgeDataFormat)
        eprintf("Missing EDGE_DATA_FORMAT specification");
    if (!FirstNode)
        CreateNodes();
    if (ProblemType == HPP)
        Dimension--;
    if (!strcmp(EdgeDataFormat, "EDGE_LIST")) {
        if (!fscanint(ProblemFile, &i))
            i = -1;
        while (i != -1) {
            if (i <= 0
                || i > (ProblemType != ATSP ? Dimension : Dimension / 2))
                eprintf("(EDGE_DATA_SECTION) Node number out of range: %d",
                        i);
            fscanint(ProblemFile, &j);
            if (j <= 0
                || j > (ProblemType != ATSP ? Dimension : Dimension / 2))
                eprintf("(EDGE_DATA_SECTION) Node number out of range: %d",
                        j);
            if (i == j)
                eprintf("(EDGE_DATA_SECTION) Illgal edge: %d to %d", i, j);
            if (ProblemType == ATSP) {
                i += Dimension / 2;
                j += Dimension / 2;
            }
            Ni = &NodeSet[i];
            Nj = &NodeSet[j];
            if (!Ni->CandidateSet) {
                Ni->V = 1;
                assert(Ni->CandidateSet =
                       (Candidate *) calloc(2, sizeof(Candidate)));
                Ni->CandidateSet[0].To = Nj;
                Ni->CandidateSet[0].Cost = 0;
            } else {
                Ni->CandidateSet[Ni->V].To = Nj;
                Ni->CandidateSet[Ni->V].Cost = 0;
                assert(Ni->CandidateSet =
                       (Candidate *) realloc(Ni->CandidateSet,
                                             (++Ni->V +
                                              1) * sizeof(Candidate)));
                Ni->CandidateSet[Ni->V].To = 0;
            }
            if (!Nj->CandidateSet) {
                Nj->V = 1;
                assert(Nj->CandidateSet =
                       (Candidate *) calloc(3, sizeof(Candidate)));
                Nj->CandidateSet[0].To = Ni;
                Nj->CandidateSet[0].Cost = 0;
            } else {
                Nj->CandidateSet[Nj->V].To = Ni;
                Nj->CandidateSet[Nj->V].Cost = 0;
                assert(Nj->CandidateSet =
                       (Candidate *) realloc(Nj->CandidateSet,
                                             (++Nj->V +
                                              1) * sizeof(Candidate)));
                Nj->CandidateSet[Nj->V].To = 0;
            }
            fscanint(ProblemFile, &i);
        }
    } else if (!strcmp(EdgeDataFormat, "ADJ_LIST")) {
        Ni = FirstNode;
        do
            Ni->V = 0;
        while ((Ni = Ni->Suc) != FirstNode);
        if (!fscanint(ProblemFile, &i))
            i = -1;
        while (i != -1) {
            if (i <= 0
                || i > (ProblemType != ATSP ? Dimension : Dimension / 2))
                eprintf("(EDGE_DATA_SECTION) Node number out of range: %d",
                        i);
            if (ProblemType == ATSP)
                i += Dimension / 2;
            Ni = &NodeSet[i];
            fscanint(ProblemFile, &j);
            while (j != -1) {
                if (j <= 0
                    || j > (ProblemType !=
                            ATSP ? Dimension : Dimension / 2))
                    eprintf
                        ("(EDGE_DATA_SECTION) Node number out of range: %d",
                         j);
                if (i == j)
                    eprintf("(EDGE_DATA_SECTION) Illgal edge: %d to %d",
                            i, j);
                if (ProblemType == ATSP)
                    j += Dimension / 2;
                Nj = &NodeSet[j];
                if (!Ni->CandidateSet) {
                    Ni->V = 1;
                    assert(Ni->CandidateSet =
                           (Candidate *) calloc(3, sizeof(Candidate)));
                    Ni->CandidateSet[0].To = Nj;
                    Ni->CandidateSet[0].Cost = 0;
                } else {
                    Ni->CandidateSet[Ni->V].To = Nj;
                    Ni->CandidateSet[Ni->V].Cost = 0;
                    assert(Ni->CandidateSet =
                           (Candidate *) realloc(Ni->CandidateSet,
                                                 (++Ni->V +
                                                  1) * sizeof(Candidate)));
                    Ni->CandidateSet[Ni->V].To = 0;
                }
                if (!Nj->CandidateSet) {
                    Nj->V = 1;
                    assert(Nj->CandidateSet =
                           (Candidate *) calloc(3, sizeof(Candidate)));
                    Nj->CandidateSet[0].To = Ni;
                    Nj->CandidateSet[0].Cost = 0;
                } else {
                    Nj->CandidateSet[Nj->V].To = Ni;
                    Nj->CandidateSet[Nj->V].Cost = 0;
                    assert(Nj->CandidateSet =
                           (Candidate *) realloc(Nj->CandidateSet,
                                                 (++Nj->V +
                                                  1) * sizeof(Candidate)));
                    Nj->CandidateSet[Nj->V].To = 0;
                }
                fscanint(ProblemFile, &j);
            }
            fscanint(ProblemFile, &i);
        }
    } else
        eprintf("(EDGE_DATA_SECTION) No EDGE_DATA_FORMAT specified");
    if (ProblemType == HPP)
        Dimension++;
    Distance = Distance_1;
}
Esempio n. 22
0
int main()
{
	//initialize random seed
	srand( (unsigned)time(NULL) );

	int amountOfNodes = -1;
	int addList = true;
	
	//first list
	ptr head;
	ptr tail;

	tail = head = (ptr)malloc(sizeof(_p));
	head->data = rand() % 100 + 1;
	head->next = NULL;

	printf("The list so far:\n");
	PrintList(head);

	//subsequent lists
	ptr head2;
	ptr tail2;

	tail2 = head2 = (ptr)malloc(sizeof(_p));
	head2->data = rand() % 100 + 1;
	head2->next = NULL;


	//first list
	while(amountOfNodes < 0)
	{
		printf("How many nodes do you want?\n");
		scanf("%d", &amountOfNodes);
		if(amountOfNodes < 0)
		{
			printf("Invalid value entered. Please enter a new value.\n");
		}
	}
	CreateNodes(amountOfNodes, tail);
	PrintList(head);


	amountOfNodes = -1;
	//add more lists
	printf("Would you like to add more lists on to the end of the current list? 1 for yes, 0 for no.\n");
	scanf("%d", &addList);

	while(addList != 0)
	{
		while(amountOfNodes < 0)
		{
			printf("How many nodes do you want?\n");
			scanf("%d", &amountOfNodes);
			if(amountOfNodes < 0)
			{
				printf("Invalid value entered. Please enter a new value.\n");
			}
		}

		CreateNodes(amountOfNodes, tail2);
		printf("The new list:\n");
		PrintList(head2);
		
		Append(head, head2);
		printf("The combined lists.\n");
		PrintList(head);

		//set tail to the end of the new combined list
		tail = head;//neccesary?
		while(tail->next != NULL)
		{
			tail = tail->next;
		}

		printf("Would you like to add more lists on to the end of the current list? 1 for yes, 0 for no.\n");
		scanf("%d", &addList);
	}

	/*
	//now to find the end of the list
	ptr temp = head;
	while(temp->next != NULL)
	{
		temp = temp->next;
	}
	*/

	////one of the ways to create a new node
	//tail->next = (ptr)malloc(sizeof(_p));
	//tail = tail->next;
	//tail->next = NULL;

	return 0;
}
Esempio n. 23
0
void Graph::Create()
{
	CreateNodes();
	CreateEdges();
}
Esempio n. 24
0
bool FXmlFile::LoadFile(const FString& InFile, EConstructMethod::Type ConstructMethod)
{
	// Remove any file stuff if it already exists
	Clear();

	// So far no error (Early so it can be overwritten below by errors)
	ErrorMessage = NSLOCTEXT("XmlParser", "LoadSuccess", "XmlFile was loaded successfully").ToString();

	TArray<FString> Input;
	if(ConstructMethod == EConstructMethod::ConstructFromFile)
	{
		// Create file reader
		TUniquePtr<FArchive> FileReader(IFileManager::Get().CreateFileReader(*InFile));
		if(!FileReader)
		{
			ErrorMessage = NSLOCTEXT("XmlParser", "FileLoadFail", "Failed to load the file").ToString();
			ErrorMessage += TEXT("\"");
			ErrorMessage += InFile;
			ErrorMessage += TEXT("\"");
			return false;
		}

		// Create buffer for file input
		uint32 BufferSize = FileReader->TotalSize();
		void* Buffer = FMemory::Malloc(BufferSize);
		FileReader->Serialize(Buffer, BufferSize);

		// Parse file buffer into an array of lines
		if (!FindCharSizeAndSplitLines(Input, Buffer, BufferSize))
		{
			ErrorMessage = NSLOCTEXT("XmlParser", "InvalidFormatFail", "Failed to parse the file (Unsupported character encoding)").ToString();
			ErrorMessage += TEXT("\"");
			ErrorMessage += InFile;
			ErrorMessage += TEXT("\"");
			return false;
		}

		// Release resources
		FMemory::Free(Buffer);
	}
	else
	{
		// Parse input buffer into an array of lines
		SplitLines(Input, *InFile, *InFile + InFile.Len());
	}

	// Pre-process the input
	PreProcessInput(Input);

	// Tokenize the input
	TArray<FString> Tokens = Tokenize(Input);

	// Parse the input & create the nodes
	CreateNodes(Tokens);

	// All done with creation, set up necessary information
	if(bFileLoaded == true)
	{
		if(ConstructMethod == EConstructMethod::ConstructFromFile)
		{
			LoadedFile = InFile;
		}
	}
	else
	{
		LoadedFile = TEXT("");
		RootNode = nullptr;
	}

	// Now check the status flag of the creation. It may have actually failed, but given us a 
	// partially created representation
	if(bCreationFailed)
	{
		Clear();
	}

	return bFileLoaded;
}
Esempio n. 25
0
 void Problem::BuildGraph()
 {
     CreateNodes();
     Link();
     SetCost();
 }
ribi::trim::TriangleMeshBuilder::TriangleMeshBuilder(
  const std::vector<boost::shared_ptr<Cell>>& cells,
  const std::string& mesh_filename,
  const std::function<ribi::foam::PatchFieldType(const std::string&)> boundary_to_patch_field_type_function
  )
  : m_cells(cells),
    m_faces(SortByBoundary(ExtractFaces(cells))),
    m_points(ExtractPoints(cells))
{
  #ifndef NDEBUG
  Test();
  #endif
  TRACE_FUNC();
  PROFILE_FUNC();

  for (const std::string& folder: GetAllFolders())
  {
    if (!ribi::fileio::IsFolder(folder))
    {
      ribi::fileio::CreateFolder(folder);
    }
    assert(ribi::fileio::IsFolder(folder));
  }

  //Remove cells with less than 8 faces or less than 8 faces with an owner
  m_cells.erase(
    std::remove_if(m_cells.begin(),m_cells.end(),
      [](const boost::shared_ptr<Cell> cell)
      {
        const std::vector<boost::shared_ptr<Face>> faces { cell->GetFaces() };
        assert(faces.size() == 8);
        return std::count_if(faces.begin(),faces.end(),
          [](const boost::shared_ptr<Face> face)
          {
            assert(face);
            assert(face->GetOwner()); //Test: is this loop needed?
            return face->GetOwner();
          }
        ) < 8;
      }
    ),
    m_cells.end()
  );


  m_faces.erase(
    std::remove_if(m_faces.begin(),m_faces.end(),
      [](const boost::shared_ptr<const Face> face)
      {
        return !face->GetOwner();
      }
    ),
    m_faces.end()
  );

  //Remove cells with less than 8 faces or less than 8 faces with an owner
  m_cells.erase(
    std::remove_if(m_cells.begin(),m_cells.end(),
      [](const boost::shared_ptr<Cell> cell)
      {
        const std::vector<boost::shared_ptr<Face>> faces { cell->GetFaces() };
        assert(faces.size() == 8);
        return std::count_if(faces.begin(),faces.end(),
          [](const boost::shared_ptr<Face> face)
          {
            assert(face);
            assert(face->GetOwner()); //Test: is this loop needed?
            return face->GetOwner();
          }
        ) < 8;
      }
    ),
    m_cells.end()
  );

  //Set all indices
  {
    const int n_cells = static_cast<int>(m_cells.size());
    for (int i=0; i!=n_cells; ++i)
    {
      m_cells[i]->SetIndex(i);
    }
    const int n_faces = static_cast<int>(m_faces.size());
    for (int i=0; i!=n_faces; ++i)
    {
      m_faces[i]->SetIndex(i);
    }
    const int n_points = static_cast<int>(m_points.size());
    for (int i=0; i!=n_points; ++i)
    {
      m_points[i]->SetIndex(i);
    }
  }


  //Check
  #ifndef NDEBUG
  {
    const int cell_usecount = m_cells.empty() ? 0 : m_cells[0].use_count();
    for (const auto& cell: m_cells)
    {
      assert(cell);
      //TRACE(cell_usecount);
      //TRACE(cell.use_count());
      assert(cell.use_count() == cell_usecount && "Every Cell must have an equal use_count");
      //All Cells must have existing indices
      assert(cell->GetIndex() >= 0);
      assert(cell->GetIndex() <  static_cast<int>(m_cells.size()));
      //const int face_usecount = cell->GetFaces().empty() ? 0 : cell->GetFaces()[0].use_count();
      for (const auto& face: cell->GetFaces())
      {
        assert(face);
        //TRACE(face_usecount);
        //TRACE(face.use_count());
        //assert(std::abs(face_usecount - face.use_count()) <= 1 && "Face are used once or twice");
        //All Cells must exist of Faces with an existing index
        assert(face->GetIndex() >= 0);
        assert(face->GetIndex() <  static_cast<int>(m_faces.size()));
        //All Faces must have a Cell that owns them with an existing index
        assert(face->GetOwner()->GetIndex() >= 0);
        assert(face->GetOwner()->GetIndex() <  static_cast<int>(m_cells.size()));
        //All Faces must have either no Neighbout or a Neighbour with an existing index
        assert(!face->GetNeighbour() || face->GetNeighbour()->GetIndex() >= 0);
        assert(!face->GetNeighbour() || face->GetNeighbour()->GetIndex() <  static_cast<int>(m_cells.size()));
        for (const auto point: face->GetPoints())
        {
          assert(point);
          //All Faces must exists of Points with an existing index
          assert(point->GetIndex() >= 0);
          assert(point->GetIndex() <  static_cast<int>(m_points.size()));
        }
      }
    }
  }
  #endif

  const bool verbose = false;
  if (verbose) std::cout << "Writing output...\n";
  //Mesh
  {
    if (verbose) std::cout << "\tGenerating mesh (.ply)\n";

    std::ofstream f(mesh_filename.c_str());
    f << CreateHeader();
    f << CreateNodes();
    f << CreateFaces();
  }
  {

    std::ofstream f(ribi::foam::Filenames().GetPoints().Get().c_str());
    f << CreateOpenFoamHeader("vectorField","points","constant/polyMesh");
    f << CreateOpenFoamNodes();
  }
  {
    std::ofstream fp(ribi::foam::Filenames().GetFaces().Get().c_str());

    fp << CreateOpenFoamHeader("faceList","faces","constant/polyMesh");
    fp << CreateOpenFoamFaces();
  }
  {
    const int n_cells = static_cast<int>(m_cells.size());
    if (verbose) std::cout << "\tGenerating cells (" << n_cells << ")\n";

    std::ofstream fo(ribi::foam::Filenames().GetOwner().Get().c_str());
    std::ofstream fn(ribi::foam::Filenames().GetNeighbour().Get().c_str());

    std::stringstream fs;
    fs
      << "nPoints: " << m_points.size()
      << " nCells: " << m_cells.size()
      << " nFaces: " << m_faces.size()
    ;

    fo << CreateOpenFoamHeader(
        "labelList",
        "owner",
        "constant/polyMesh",
        fs.str()
      );
    fn << CreateOpenFoamHeader(
      "labelList",
      "neighbour",
      "constant/polyMesh",
      fs.str()
      );

    const std::pair<std::string,std::string> p { CreateCells() };
    const std::string& out_owner { p.first };
    const std::string& out_neighbour { p.second};
    fo << out_owner;
    fn << out_neighbour;
  }
  {
    std::ofstream f(ribi::foam::Filenames().GetBoundary().Get().c_str());
    f << CreateBoundary(boundary_to_patch_field_type_function);
  }
  {
    std::ofstream f(ribi::foam::Filenames().GetCase().Get().c_str());
    //Need nothing to stream
  }
  {
    //std::ofstream f(ribi::foam::Filenames().GetFvSchemes().Get().c_str());
    //f << CreateOpenFoamFvSchemes();
  }
  {
    //std::ofstream f(ribi::foam::Filenames().GetFvSolution().Get().c_str());
    //f << CreateOpenFoamFvSolution();
  }

  {
    std::ofstream f(ribi::foam::Filenames().GetVelocityField().Get().c_str());
    f << CreateOpenFoamU();
  }

  {
    //std::ofstream f(ribi::foam::Filenames().GetControlDict().Get().c_str());
    //f << CreateOpenFoamControlDict();
  }

  PROFILER_UPDATE();
}
Esempio n. 27
0
static void Read_EDGE_WEIGHT_SECTION()
{
    Node *Ni, *Nj;
    int i, j, n, W;

    CheckSpecificationPart();
    if (!FirstNode)
        CreateNodes();
    if (ProblemType != ATSP) {
        assert(CostMatrix =
               (int *) calloc((size_t) Dimension * (Dimension - 1) / 2,
                              sizeof(int)));
        Ni = FirstNode->Suc;
        do {
            Ni->C =
                &CostMatrix[(size_t) (Ni->Id - 1) * (Ni->Id - 2) / 2] - 1;
        }
        while ((Ni = Ni->Suc) != FirstNode);
    } else {
        n = Dimension / 2;
        assert(CostMatrix = (int *) calloc((size_t) n * n, sizeof(int)));
        for (Ni = FirstNode; Ni->Id <= n; Ni = Ni->Suc)
            Ni->C = &CostMatrix[(size_t) (Ni->Id - 1) * n] - 1;
    }
    if (ProblemType == HPP)
        Dimension--;
    switch (WeightFormat) {
    case FULL_MATRIX:
        if (ProblemType == ATSP) {
            n = Dimension / 2;
            for (i = 1; i <= n; i++) {
                Ni = &NodeSet[i];
                for (j = 1; j <= n; j++) {
                    if (!fscanint(ProblemFile, &W))
                        eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                    if (W > INT_MAX / 2 / Precision)
                        W = INT_MAX / 2 / Precision;
                    Ni->C[j] = W;
                    if (i != j && W > M)
                        M = W;
                }
                Nj = &NodeSet[i + n];
                if (!Ni->FixedTo1)
                    Ni->FixedTo1 = Nj;
                else if (!Ni->FixedTo2)
                    Ni->FixedTo2 = Nj;
                if (!Nj->FixedTo1)
                    Nj->FixedTo1 = Ni;
                else if (!Nj->FixedTo2)
                    Nj->FixedTo2 = Ni;
            }
            Distance = Distance_ATSP;
            WeightType = -1;
        } else
            for (i = 1, Ni = FirstNode; i <= Dimension; i++, Ni = Ni->Suc) {
                for (j = 1; j <= Dimension; j++) {
                    if (!fscanint(ProblemFile, &W))
                        eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                    if (W > INT_MAX / 2 / Precision)
                        W = INT_MAX / 2 / Precision;
                    if (j < i)
                        Ni->C[j] = W;
                }
            }
        break;
    case UPPER_ROW:
        for (i = 1, Ni = FirstNode; i < Dimension; i++, Ni = Ni->Suc) {
            for (j = i + 1, Nj = Ni->Suc; j <= Dimension;
                 j++, Nj = Nj->Suc) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                if (W > INT_MAX / 2 / Precision)
                    W = INT_MAX / 2 / Precision;
                Nj->C[i] = W;
            }
        }
        break;
    case LOWER_ROW:
        for (i = 2, Ni = FirstNode->Suc; i <= Dimension; i++, Ni = Ni->Suc) {
            for (j = 1; j < i; j++) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                if (W > INT_MAX / 2 / Precision)
                    W = INT_MAX / 2 / Precision;
                Ni->C[j] = W;
            }
        }
        break;
    case UPPER_DIAG_ROW:
        for (i = 1, Ni = FirstNode; i <= Dimension; i++, Ni = Ni->Suc) {
            for (j = i, Nj = Ni; j <= Dimension; j++, Nj = Nj->Suc) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                if (W > INT_MAX / 2 / Precision)
                    W = INT_MAX / 2 / Precision;
                if (i != j)
                    Nj->C[i] = W;
            }
        }
        break;
    case LOWER_DIAG_ROW:
        for (i = 1, Ni = FirstNode; i <= Dimension; i++, Ni = Ni->Suc) {
            for (j = 1; j <= i; j++) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                if (W > INT_MAX / 2 / Precision)
                    W = INT_MAX / 2 / Precision;
                if (j != i)
                    Ni->C[j] = W;
            }
        }
        break;
    case UPPER_COL:
        for (j = 2, Nj = FirstNode->Suc; j <= Dimension; j++, Nj = Nj->Suc) {
            for (i = 1; i < j; i++) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                if (W > INT_MAX / 2 / Precision)
                    W = INT_MAX / 2 / Precision;
                Nj->C[i] = W;
            }
        }
        break;
    case LOWER_COL:
        for (j = 1, Nj = FirstNode; j < Dimension; j++, Nj = Nj->Suc) {
            for (i = j + 1, Ni = Nj->Suc; i <= Dimension;
                 i++, Ni = Ni->Suc) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                Ni->C[j] = W;
            }
        }
        break;
    case UPPER_DIAG_COL:
        for (j = 1, Nj = FirstNode; j <= Dimension; j++, Nj = Nj->Suc) {
            for (i = 1; i <= j; i++) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                if (W > INT_MAX / 2 / Precision)
                    W = INT_MAX / 2 / Precision;
                if (i != j)
                    Nj->C[i] = W;
            }
        }
        break;
    case LOWER_DIAG_COL:
        for (j = 1, Nj = FirstNode; j <= Dimension; j++, Nj = Nj->Suc) {
            for (i = j, Ni = Nj; i <= Dimension; i++, Ni = Ni->Suc) {
                if (!fscanint(ProblemFile, &W))
                    eprintf("Missing weight in EDGE_WEIGHT_SECTION");
                if (W > INT_MAX / 2 / Precision)
                    W = INT_MAX / 2 / Precision;
                if (i != j)
                    Ni->C[j] = W;
            }
        }
        break;
    }
    if (ProblemType == HPP)
        Dimension++;
}
Esempio n. 28
0
static void Read_TOUR_SECTION(FILE ** File)
{
    Node *First = 0, *Last = 0, *N, *Na;
    int i, k;

    if (TraceLevel >= 1) {
        printff("Reading ");
        if (File == &InitialTourFile)
            printff("INITIAL_TOUR_FILE: \"%s\" ... ", InitialTourFileName);
        else if (File == &InputTourFile)
            printff("INPUT_TOUR_FILE: \"%s\" ... ", InputTourFileName);
        else if (File == &SubproblemTourFile)
            printff("SUBPROBLEM_TOUR_FILE: \"%s\" ... ",
                    SubproblemTourFileName);
        else
            for (i = 0; i < MergeTourFiles; i++)
                if (File == &MergeTourFile[i])
                    printff("MERGE_TOUR_FILE: \"%s\" ... ",
                            MergeTourFileName[i]);
    }
    if (!FirstNode)
        CreateNodes();
    N = FirstNode;
    do
        N->V = 0;
    while ((N = N->Suc) != FirstNode);
    if (ProblemType == HPP)
        Dimension--;
    if (ProblemType == ATSP)
        Dimension /= 2;
    if (!fscanint(*File, &i))
        i = -1;
    for (k = 0; k <= Dimension && i != -1; k++) {
        if (i <= 0 || i > Dimension)
            eprintf("(TOUR_SECTION) Node number out of range: %d", i);
        N = &NodeSet[i];
        if (N->V == 1 && k != Dimension)
            eprintf("(TOUR_SECTION) Node number occurs twice: %d", N->Id);
        N->V = 1;
        if (k == 0)
            First = Last = N;
        else {
            if (ProblemType == ATSP) {
                Na = N + Dimension;
                Na->V = 1;
            } else
                Na = 0;
            if (File == &InitialTourFile) {
                if (!Na)
                    Last->InitialSuc = N;
                else {
                    Last->InitialSuc = Na;
                    Na->InitialSuc = N;
                }
            } else if (File == &InputTourFile) {
                if (!Na)
                    Last->InputSuc = N;
                else {
                    Last->InputSuc = Na;
                    Na->InputSuc = N;
                }
            } else if (File == &SubproblemTourFile) {
                if (!Na)
                    (Last->SubproblemSuc = N)->SubproblemPred = Last;
                else {
                    (Last->SubproblemSuc = Na)->SubproblemPred = Last;
                    (Na->SubproblemSuc = N)->SubproblemPred = Na;
                }
            } else {
                for (i = 0; i < MergeTourFiles; i++) {
                    if (File == &MergeTourFile[i]) {
                        if (!Na)
                            Last->MergeSuc[i] = N;
                        else {
                            Last->MergeSuc[i] = Na;
                            Na->MergeSuc[i] = N;
                        }
                    }
                }
            }
            Last = N;
        }
        if (k < Dimension)
            fscanint(*File, &i);
        if (k == Dimension - 1)
            i = First->Id;
    }
    N = FirstNode;
    do
        if (!N->V)
            eprintf("(TOUR_SECTION) Node is missing: %d", N->Id);
    while ((N = N->Suc) != FirstNode);
    if (File == &SubproblemTourFile) {
        do {
            if (N->FixedTo1 &&
                N->SubproblemPred != N->FixedTo1
                && N->SubproblemSuc != N->FixedTo1)
                eprintf("Fixed edge (%d, %d) "
                        "does not belong to subproblem tour", N->Id,
                        N->FixedTo1->Id);
            if (N->FixedTo2 && N->SubproblemPred != N->FixedTo2
                && N->SubproblemSuc != N->FixedTo2)
                eprintf("Fixed edge (%d, %d) "
                        "does not belong to subproblem tour", N->Id,
                        N->FixedTo2->Id);
        } while ((N = N->Suc) != FirstNode);
    }
    if (ProblemType == HPP)
        Dimension++;
    if (ProblemType == ATSP)
        Dimension *= 2;
    if (TraceLevel >= 1)
        printff("done\n");
}