Hello,
I am not able to compile it on windows. It compiles fine in linux but not on windows. Well actually it compiles if i change a few things but there are many linker errors. Could someonline please tell me where the problem is at.
Thanks

// Project: B*-trees floorplanning
// Advisor: Yao-Wen Chang  <ywchang@cis.nctu.edu.tw>
// Authors: Jer-Ming Hsu   <barz@cis.nctu.edu.tw>
// 	    Hsun-Cheng Lee <gis88526@cis.nctu.edu.tw>
// Sponsor: Arcadia Inc.
// Date:    7/19/2000 ~

//---------------------------------------------------------------------------
#include "fplan.h"
#include <fstream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <ctime>
#include "Resource.h"
#include <iostream>
#include <cassert>

//---------------------------------------------------------------------------
char line[100],t1[40],t2[40];
ifstream fs;

FPlan::FPlan(float calpha=1){
  norm_area= 1;
  norm_wire= 1;
  cost_alpha=calpha;
}

void FPlan::packing(){
  if(cost_alpha!=1)
     calcWireLength();
}

void FPlan::clear(){
  Area = 0; 
  WireLength = 0;
}

double FPlan::getCost(){
  if(cost_alpha==1)
     return cost_alpha*(Area/norm_area);
  else if(cost_alpha < 1e-4)
     return (WireLength/norm_wire);
  else
     return cost_alpha*(Area/norm_area)+(1-cost_alpha)*(WireLength/norm_wire);
}

float FPlan::getDeadSpace(){
  return 100*(Area-TotalArea)/float(Area);
}

void FPlan::normalize_cost(int t){
  norm_area=norm_wire=0;

  for(int i=0; i < t; i++){
    perturb();
    packing();
    norm_area += Area;
    norm_wire += WireLength;
  }
  
  norm_area /= t;
  norm_wire /= t;
  printf("normalize area=%.0f, wire=%.0f\n", norm_area, norm_wire);
}

//---------------------------------------------------------------------------
//   Read
//---------------------------------------------------------------------------

char* tail(char *str){
    str[strlen(str)-1]=0;
    return str;
}

void FPlan::read(char *file){
  filename = file; 
  fs.open(file);
  if(fs==NULL)
    error("unable to open file: %s",file);

  bool final=false;
  Module dummy_mod;
  for(int i=0; !fs.eof(); i++){
    // modules
    modules.push_back(dummy_mod);	// new module
    Module &mod = modules.back();
    mod.id = i;
    mod.pins.clear();

    fs >> t1 >> t2;
    tail(t2);			// remove ";"
    strcpy(mod.name,t2);

    fs >> t1 >> t2;
    if(!strcmp(t2,"PARENT;"))
	final= true;
    
    // dimension
    read_dimension(mod);    
    read_IO_list(mod,final);

    // network
    if(final){
      read_network();
      break;
    }
  }

  root_module = modules.back();
  modules.pop_back();		// exclude the parent module
  modules_N = modules.size();  
  modules_info.resize(modules_N);
  modules.resize(modules_N);

  create_network();

  TotalArea = 0;
  for(int i=0; i < modules_N; i++)
    TotalArea += modules[i].area;

}

void FPlan::read_dimension(Module &mod){
    fs >> t1;
    int min_x=INT_MAX,min_y=INT_MAX,max_x=INT_MIN,max_y=INT_MIN;
    int tx,ty;
    for(int i=0; i < 4;i++){
      fs >> tx >> ty; 
      min_x=min(min_x,tx); max_x=max(max_x,tx);
      min_y=min(min_y,ty); max_y=max(max_y,ty);
    }

    mod.x      = min_x;
    mod.y      = min_y;
    mod.width  = max_x - min_x;
    mod.height = max_y - min_y;
    mod.area   = mod.width * mod.height;
    fs >> t1 >> t2;
}

void FPlan::read_IO_list(Module &mod,bool parent=false){
    // IO list
    while(!fs.eof()){
      Pin p;
      fs.getline(line,100);
      if(strlen(line)==0) continue;
      sscanf(line,"%s %*s %d %d",t1,&p.x,&p.y);

      if(!strcmp(t1,"ENDIOLIST;"))
	break;

      if(parent){ // IO pad is network
       // make unique net id
        net_table.insert(make_pair(string(t1),net_table.size()));
        p.net = net_table[t1];
      }

      p.mod = mod.id;
      p.x -= mod.x;  p.y -= mod.y;	// shift to origin

      mod.pins.push_back(p);
    }
    fs.getline(line,100);
}

void FPlan::read_network(){
    while(!fs.eof()){
      bool end=false;
      int n=0;
      fs >> t1 >> t2;
      if(!strcmp(t1,"ENDNETWORK;"))
        break;
      // determine which module interconnection by name
      int m_id;
      for(m_id=0; m_id < modules.size(); m_id++)
        if(!strcmp(modules[m_id].name,t2))
   	  break;
      if(m_id== modules.size())
 	error("can't find suitable module name!");
        
      while(!fs.eof()){
        fs >> t1;
        if(t1[strlen(t1)-1]==';'){
 	  tail(t1);
          end=true;
        }

        // make unique net id
        net_table.insert(make_pair(string(t1),net_table.size()));
        modules[m_id].pins[n++].net = net_table[t1];
        if(end) break;
      }
    }
}

//---------------------------------------------------------------------------
//   Wire Length Estimate
//---------------------------------------------------------------------------

void FPlan::create_network(){
  network.resize(net_table.size());

  for(int i=0; i < modules_N; i++){
    for(int j=0; j < modules[i].pins.size(); j++){
      Pin &p = modules[i].pins[j];
      network[p.net].push_back(&p);
    }
  }

  for(int j=0; j < root_module.pins.size(); j++){
    Pin &p = root_module.pins[j];
    network[p.net].push_back(&p);
  }

  connection.resize(modules_N+1);
  for(int i=0; i < modules_N+1; i++){
    connection[i].resize(modules_N+1);
    fill(connection[i].begin(), connection[i].end(), 0);
  }

  for(int i=0; i < network.size(); i++){
    for(int j=0; j < network[i].size()-1; j++){
      int p= network[i][j]->mod;
      for(int k=j+1 ; k < network[i].size(); k++){
        int q= network[i][k]->mod;
        connection[p][q]++;
        connection[q][p]++;   
      }
    }
  }
}


void FPlan::scaleIOPad(){
  float px = Width/float(root_module.width);
  float py = Height/float(root_module.height);
    
  for(int i=0; i < root_module.pins.size(); i++){
    Pin &p = root_module.pins[i];
    p.ax = int(px * p.x);
    p.ay = int(py * p.y);
    
  }      
}

double FPlan::calcWireLength(){

  scaleIOPad();
 
  WireLength=0;
  // compute absolute position
  for(int i=0; i < modules_N; i++){   
    int mx= modules_info[i].x, my= modules_info[i].y;
    bool rotate= modules_info[i].rotate;
    int w= modules[i].width;

    for(int j=0; j < modules[i].pins.size(); j++){
      Pin &p = modules[i].pins[j];

      if(!rotate){      
        p.ax= p.x+mx, p.ay= p.y+my;
      }
      else{ // Y' = W - X, X' = Y
	p.ax= p.y+mx, p.ay= (w-p.x)+my;
      } 
    }
  }

  for(int i=0; i < network.size(); i++){     
    int max_x= INT_MIN, max_y= INT_MIN;      
    int min_x= INT_MAX, min_y= INT_MAX;      

    assert(network[i].size() > 0);
    for(int j=0; j < network[i].size(); j++){
      Pin &p = *network[i][j];
      max_x= max(max_x, p.ax), max_y= max(max_y, p.ay);
      min_x= min(min_x, p.ax), min_y= min(min_y, p.ay);
    }
//    printf("%d %d %d %d\n",max_x,min_x,max_y,min_y);
    WireLength += (max_x-min_x)+(max_y-min_y);
  }
  return WireLength;
}

//---------------------------------------------------------------------------
//   Modules Information
//---------------------------------------------------------------------------

string query_map(map<string,int> M,int value){
  for(map<string,int>::iterator p=M.begin(); p != M.end(); p++){
    if(p->second == value)
      return p->first;
  }
  return "";
}

void FPlan::show_modules()
{
  for(int i=0; i < modules.size();i++){
    cout << "Module: " << modules[i].name << endl;
    cout << "  Width = " << modules[i].width;
    cout << "  Height= " << modules[i].height << endl;
    cout << "  Area  = " << modules[i].area << endl;
//    cout << modules[i].pins.size() << " Pins:\n";
//    for(int j=0; j < modules[i].pins.size(); j++){
//      cout << query_map(net_table,modules[i].pins[j].net) << " ";
//      cout << modules[i].pins[j].x << " " << modules[i].pins[j].y << endl;
//    }
  }
}

void FPlan::list_information(){

  string info = filename + ".info";   
  ofstream of(info.c_str());
  
  of << modules_N << " " << Width << " " << Height << endl;
  for(int i=0; i < modules_N; i++){
    of << modules_info[i].x  << " " << modules_info[i].rx  << " ";
    of << modules_info[i].y << " " << modules_info[i].ry << endl;
  }
  of << endl;

  calcWireLength(); 
  int x,y,rx,ry;
  for(int i=0; i < network.size(); i++){
    assert(network[i].size()>0);
    x = network[i][0]->ax;
    y = network[i][0]->ay;
    
    for(int j=1; j < network[i].size(); j++){
      rx = network[i][j]->ax;
      ry = network[i][j]->ay;
      of << x << " " << y << " " << rx << " " << ry << endl;
      x = rx, y = ry;
    }
  }

  cout << "Num of Module  = " << modules_N << endl;
  cout << "Height         = " << Height*1e-3 << endl;
  cout << "Width          = " << Width*1e-3 << endl;
  cout << "Area           = " << Area*1e-6 << endl;
  cout << "Wire Length    = " << calcWireLength()*1e-3 << endl;
  cout << "Total Area     = " << TotalArea*1e-6 << endl;
  printf( "Dead Space     = %.2f\n", getDeadSpace());
}

//---------------------------------------------------------------------------
//   Auxilliary Functions
//---------------------------------------------------------------------------

void error(char *msg,char *msg2){
  printf(msg,msg2);
  cout << endl;
  throw 1;
}

bool rand_bool(){
  return bool(rand()%2);
}

float rand_01(){
  return float(rand()%10000)/10000;
}

double seconds(){
   rusage time;
   getrusage(RUSAGE_SELF,&time);
   return (double)(1.0*time.ru_utime.tv_sec+0.000001*time.ru_utime.tv_usec);
}

There is another file which contains

// Project: B*-trees floorplanning
// Advisor: Yao-Wen Chang  <ywchang@cis.nctu.edu.tw>
// Authors: Jer-Ming Hsu   <barz@cis.nctu.edu.tw>
// 	    Hsun-Cheng Lee <gis88526@cis.nctu.edu.tw>
// Sponsor: Arcadia Inc.
// Date:    7/19/2000 ~

//---------------------------------------------------------------------------
#ifndef fplanH
#define fplanH
//---------------------------------------------------------------------------
#include <vector>
#include <string>
#include <fstream>
#include <map>
#include <cstdio>
//---------------------------------------------------------------------------
using namespace std;

struct Pin{
  int mod;
  int net;
  int x,y;    // relative position
  int ax,ay;  // absolute position
  Pin(int x_=-1,int y_=-1){ x=x_,y=y_; }
};
typedef vector<Pin> Pins;
typedef Pin* Pin_p;
typedef vector<Pin_p> Net;
typedef vector<Net > Nets;

enum Module_Type { MT_Hard, MT_Soft, MT_Reclinear, MT_Buffer };

struct Module{
  int id;
  char name[20];
  int width,height;
  int x,y;
  int area;
  Pins pins;
  Module_Type type;
};
typedef vector<Module> Modules;

struct Module_Info{
  bool rotate, flip;
  int x,y;
  int rx,ry;
};

typedef vector<Module_Info> Modules_Info;

class FPlan{
  public:
    FPlan(float calpha);
    void read(char*);
    virtual void init()		=0;
    virtual void packing();
    virtual void perturb()	=0;    
    virtual void keep_sol()	=0;
    virtual void keep_best()	=0;
    virtual void recover()	=0;
    virtual void recover_best() =0;
    virtual double getCost();    

    int    size()         { return modules_N; }
    double getTotalArea() { return TotalArea; }
    double getArea()      { return Area;      }
    int    getWireLength(){ return WireLength;}
    double getWidth()     { return Width;     }
    double getHeight()    { return Height;    }
    float  getDeadSpace();

    // information
    void list_information();
    void show_modules();    
    void normalize_cost(int);
    
  protected:
    void clear();
    double calcWireLength();
    void scaleIOPad(); 

    double Area;
    double Width,Height;
    int WireLength;
    double TotalArea;
    
    int modules_N;    
    Modules modules;
    Module  root_module;
    Modules_Info modules_info;    
    Nets network;
    double norm_area, norm_wire;
    float cost_alpha;
    vector<vector<int> > connection;
    
  private:
    void read_dimension(Module&);
    void read_IO_list(Module&,bool parent);
    void read_network();
    void create_network();   

    map<string,int> net_table;
    string filename; 
};


void error(char *msg,char *msg2="");
bool rand_bool();
float rand_01();
double seconds();
      
//---------------------------------------------------------------------------
#endif

And another file

//---------------------------------------------------------------------------
#ifndef sa_btreeH
#define sa_btreeH
//---------------------------------------------------------------------------
#include "fplan.h"
//---------------------------------------------------------------------------
extern float init_avg;
extern float avg_ratio;
extern float lamda;

double SA_Floorplan(FPlan &fp, int k, int local=0, float term_T=0.1);
double Random_Floorplan(FPlan &fp,int times);
//---------------------------------------------------------------------------
#endif

i am sure the problem is in the header file equavlency of windows and linux. is there a way i can find the windows equivlent of header file of linux?
Thanks

It seems that the code uses getrusage() , which is not available on Windows. You can use GetProcessTimes() on Windows.

actually it compiles if i change a few things but there are many linker errors. Could someonline please tell me where the problem is at

You could have been more specific about the errors/warnings that you are receiving.

I have replaced that but there are still a lot of errors.

1>------ Build started: Project: code, Configuration: Debug Win32 ------
1>Compiling...
1>fplan.cc
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(49) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(93) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(148) : warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(324) : see declaration of 'sscanf'
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(176) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(205) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(211) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(222) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(223) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(225) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(236) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(237) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(239) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(258) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(270) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(275) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(300) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(327) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(332) : warning C4018: '<' : signed/unsigned mismatch
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(360) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(368) : error C2065: 'rusage' : undeclared identifier
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(368) : error C2146: syntax error : missing ';' before identifier 'time'
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(368) : warning C4551: function call missing argument list
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(369) : error C2065: 'RUSAGE_SELF' : undeclared identifier
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(369) : error C3861: 'GetProcessTimes': identifier not found
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(370) : error C2228: left of '.ru_utime' must have class/struct/union
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(370) : error C2228: left of '.tv_sec' must have class/struct/union
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(370) : error C2228: left of '.ru_utime' must have class/struct/union
1>e:\3dfloorplanning\visual studio 2008\projects\code\code\fplan.cc(370) : error C2228: left of '.tv_usec' must have class/struct/union
1>Build log was saved at "file://e:\3DFloorplanning\Visual Studio 2008\Projects\code\code\Debug\BuildLog.htm"
1>code - 8 error(s), 20 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

When you compile on Windows, don't include the following headers:
<sys/time.h> and <sys/resource.h> but <windows.h> instead.

Then ...

  • use GetProcessTimes() instead of getrusage()
  • add necessary C++ headers, such as <iostream>, also <cassert>
  • handle "redefinition of default parameter" errors (i.e. delete default parameters from the function/method definitions
  • handle warnings such as 'possible loss of data' and 'truncation of data' etc ...

Thanks i get the last on. I am having another problem. I am using #include <windows.h> to use GetProcessTimes() but i keep on getting the error, error C2660: 'GetProcessTimes' : function does not take 2 arguments. I have tried a lot of different ways this error just does not seem to go away. Any help would be appreciated.
Thanks

// Project: B*-trees floorplanning
// Advisor: Yao-Wen Chang  <ywchang@cis.nctu.edu.tw>
// Authors: Jer-Ming Hsu   <barz@cis.nctu.edu.tw>
// 	    Hsun-Cheng Lee <gis88526@cis.nctu.edu.tw>
// Sponsor: Arcadia Inc.
// Date:    7/19/2000 ~

//---------------------------------------------------------------------------
#include "fplan.h"
#include <fstream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <ctime>
#include "Resource.h"
#include <iostream>
#include <cassert>
#include <Windows.h>

//---------------------------------------------------------------------------
char line[100],t1[40],t2[40];
ifstream fs;

FPlan::FPlan(float calpha=1){
  norm_area= 1;
  norm_wire= 1;
  cost_alpha=calpha;
}

void FPlan::packing(){
  if(cost_alpha!=1)
     calcWireLength();
}

void FPlan::clear(){
  Area = 0; 
  WireLength = 0;
}

double FPlan::getCost(){
  if(cost_alpha==1)
     return cost_alpha*(Area/norm_area);
  else if(cost_alpha < 1e-4)
     return (WireLength/norm_wire);
  else
     return cost_alpha*(Area/norm_area)+(1-cost_alpha)*(WireLength/norm_wire);
}

float FPlan::getDeadSpace(){
  return 100*(Area-TotalArea)/float(Area);
}

void FPlan::normalize_cost(int t){
  norm_area=norm_wire=0;

  for(int i=0; i < t; i++){
    perturb();
    packing();
    norm_area += Area;
    norm_wire += WireLength;
  }
  
  norm_area /= t;
  norm_wire /= t;
  printf("normalize area=%.0f, wire=%.0f\n", norm_area, norm_wire);
}

//---------------------------------------------------------------------------
//   Read
//---------------------------------------------------------------------------

char* tail(char *str){
    str[strlen(str)-1]=0;
    return str;
}

void FPlan::read(char *file){
  filename = file; 
  fs.open(file);
  if(fs==NULL)
    error("unable to open file: %s",file);

  bool final=false;
  Module dummy_mod;
  for(int i=0; !fs.eof(); i++){
    // modules
    modules.push_back(dummy_mod);	// new module
    Module &mod = modules.back();
    mod.id = i;
    mod.pins.clear();

    fs >> t1 >> t2;
    tail(t2);			// remove ";"
    strcpy(mod.name,t2);

    fs >> t1 >> t2;
    if(!strcmp(t2,"PARENT;"))
	final= true;
    
    // dimension
    read_dimension(mod);    
    read_IO_list(mod,final);

    // network
    if(final){
      read_network();
      break;
    }
  }

  root_module = modules.back();
  modules.pop_back();		// exclude the parent module
  modules_N = modules.size();  
  modules_info.resize(modules_N);
  modules.resize(modules_N);

  create_network();

  TotalArea = 0;
  for(int i=0; i < modules_N; i++)
    TotalArea += modules[i].area;

}

void FPlan::read_dimension(Module &mod){
    fs >> t1;
    int min_x=INT_MAX,min_y=INT_MAX,max_x=INT_MIN,max_y=INT_MIN;
    int tx,ty;
    for(int i=0; i < 4;i++){
      fs >> tx >> ty; 
      min_x=min(min_x,tx); max_x=max(max_x,tx);
      min_y=min(min_y,ty); max_y=max(max_y,ty);
    }

    mod.x      = min_x;
    mod.y      = min_y;
    mod.width  = max_x - min_x;
    mod.height = max_y - min_y;
    mod.area   = mod.width * mod.height;
    fs >> t1 >> t2;
}

void FPlan::read_IO_list(Module &mod,bool parent=false){
    // IO list
    while(!fs.eof()){
      Pin p;
      fs.getline(line,100);
      if(strlen(line)==0) continue;
      sscanf(line,"%s %*s %d %d",t1,&p.x,&p.y);

      if(!strcmp(t1,"ENDIOLIST;"))
	break;

      if(parent){ // IO pad is network
       // make unique net id
        net_table.insert(make_pair(string(t1),net_table.size()));
        p.net = net_table[t1];
      }

      p.mod = mod.id;
      p.x -= mod.x;  p.y -= mod.y;	// shift to origin

      mod.pins.push_back(p);
    }
    fs.getline(line,100);
}

void FPlan::read_network(){
    while(!fs.eof()){
      bool end=false;
      int n=0;
      fs >> t1 >> t2;
      if(!strcmp(t1,"ENDNETWORK;"))
        break;
      // determine which module interconnection by name
      int m_id;
      for(m_id=0; m_id < modules.size(); m_id++)
        if(!strcmp(modules[m_id].name,t2))
   	  break;
      if(m_id== modules.size())
 	error("can't find suitable module name!");
        
      while(!fs.eof()){
        fs >> t1;
        if(t1[strlen(t1)-1]==';'){
 	  tail(t1);
          end=true;
        }

        // make unique net id
        net_table.insert(make_pair(string(t1),net_table.size()));
        modules[m_id].pins[n++].net = net_table[t1];
        if(end) break;
      }
    }
}

//---------------------------------------------------------------------------
//   Wire Length Estimate
//---------------------------------------------------------------------------

void FPlan::create_network(){
  network.resize(net_table.size());

  for(int i=0; i < modules_N; i++){
    for(int j=0; j < modules[i].pins.size(); j++){
      Pin &p = modules[i].pins[j];
      network[p.net].push_back(&p);
    }
  }

  for(int j=0; j < root_module.pins.size(); j++){
    Pin &p = root_module.pins[j];
    network[p.net].push_back(&p);
  }

  connection.resize(modules_N+1);
  for(int i=0; i < modules_N+1; i++){
    connection[i].resize(modules_N+1);
    fill(connection[i].begin(), connection[i].end(), 0);
  }

  for(int i=0; i < network.size(); i++){
    for(int j=0; j < network[i].size()-1; j++){
      int p= network[i][j]->mod;
      for(int k=j+1 ; k < network[i].size(); k++){
        int q= network[i][k]->mod;
        connection[p][q]++;
        connection[q][p]++;   
      }
    }
  }
}


void FPlan::scaleIOPad(){
  float px = Width/float(root_module.width);
  float py = Height/float(root_module.height);
    
  for(int i=0; i < root_module.pins.size(); i++){
    Pin &p = root_module.pins[i];
    p.ax = int(px * p.x);
    p.ay = int(py * p.y);
    
  }      
}

double FPlan::calcWireLength(){

  scaleIOPad();
 
  WireLength=0;
  // compute absolute position
  for(int i=0; i < modules_N; i++){   
    int mx= modules_info[i].x, my= modules_info[i].y;
    bool rotate= modules_info[i].rotate;
    int w= modules[i].width;

    for(int j=0; j < modules[i].pins.size(); j++){
      Pin &p = modules[i].pins[j];

      if(!rotate){      
        p.ax= p.x+mx, p.ay= p.y+my;
      }
      else{ // Y' = W - X, X' = Y
	p.ax= p.y+mx, p.ay= (w-p.x)+my;
      } 
    }
  }

  for(int i=0; i < network.size(); i++){     
    int max_x= INT_MIN, max_y= INT_MIN;      
    int min_x= INT_MAX, min_y= INT_MAX;      

    assert(network[i].size() > 0);
    for(int j=0; j < network[i].size(); j++){
      Pin &p = *network[i][j];
      max_x= max(max_x, p.ax), max_y= max(max_y, p.ay);
      min_x= min(min_x, p.ax), min_y= min(min_y, p.ay);
    }
//    printf("%d %d %d %d\n",max_x,min_x,max_y,min_y);
    WireLength += (max_x-min_x)+(max_y-min_y);
  }
  return WireLength;
}

//---------------------------------------------------------------------------
//   Modules Information
//---------------------------------------------------------------------------

string query_map(map<string,int> M,int value){
  for(map<string,int>::iterator p=M.begin(); p != M.end(); p++){
    if(p->second == value)
      return p->first;
  }
  return "";
}

void FPlan::show_modules()
{
  for(int i=0; i < modules.size();i++){
    cout << "Module: " << modules[i].name << endl;
    cout << "  Width = " << modules[i].width;
    cout << "  Height= " << modules[i].height << endl;
    cout << "  Area  = " << modules[i].area << endl;
//    cout << modules[i].pins.size() << " Pins:\n";
//    for(int j=0; j < modules[i].pins.size(); j++){
//      cout << query_map(net_table,modules[i].pins[j].net) << " ";
//      cout << modules[i].pins[j].x << " " << modules[i].pins[j].y << endl;
//    }
  }
}

void FPlan::list_information(){

  string info = filename + ".info";   
  ofstream of(info.c_str());
  
  of << modules_N << " " << Width << " " << Height << endl;
  for(int i=0; i < modules_N; i++){
    of << modules_info[i].x  << " " << modules_info[i].rx  << " ";
    of << modules_info[i].y << " " << modules_info[i].ry << endl;
  }
  of << endl;

  calcWireLength(); 
  int x,y,rx,ry;
  for(int i=0; i < network.size(); i++){
    assert(network[i].size()>0);
    x = network[i][0]->ax;
    y = network[i][0]->ay;
    
    for(int j=1; j < network[i].size(); j++){
      rx = network[i][j]->ax;
      ry = network[i][j]->ay;
      of << x << " " << y << " " << rx << " " << ry << endl;
      x = rx, y = ry;
    }
  }

  cout << "Num of Module  = " << modules_N << endl;
  cout << "Height         = " << Height*1e-3 << endl;
  cout << "Width          = " << Width*1e-3 << endl;
  cout << "Area           = " << Area*1e-6 << endl;
  cout << "Wire Length    = " << calcWireLength()*1e-3 << endl;
  cout << "Total Area     = " << TotalArea*1e-6 << endl;
  printf( "Dead Space     = %.2f\n", getDeadSpace());
}

//---------------------------------------------------------------------------
//   Auxilliary Functions
//---------------------------------------------------------------------------

void error(char *msg,char *msg2){
  printf(msg,msg2);
  cout << endl;
  throw 1;
}

bool rand_bool(){
  return bool(rand()%2);
}

float rand_01(){
  return float(rand()%10000)/10000;
}
double rusage, RUSAGE_SELF;
double seconds(){
   rusage time;
   GetProcessTimes(RUSAGE_SELF,&time); //GetProcessTimes() for windows instead of getrusage()
   return (double)(1.0*time.ru_utime.tv_sec+0.000001*time.ru_utime.tv_usec);
}

Hmm, that certainly will not work. You haven't paid too much attention to the GetProcessTimes() documentation.

Below is code that tries to get the information you are after. If it succeeds, you can incorporate that functionality into your program (e.g. make it a function of its own) . See if it works on your system ...

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
  // get the current process' id, this should pretty 
  // much always succeed ...
  const DWORD PID = GetCurrentProcessId();

  // try to get a handle to this process
  const HANDLE hProcess = OpenProcess(
    PROCESS_QUERY_INFORMATION,
    FALSE,
    PID);

  // was it a success ?
  if(hProcess == NULL)
  {
    // no ...
    cout << "OpenProcess() failed, error: " << GetLastError() << endl;
    return 0;
  }

  FILETIME CreationTime = {0};
  FILETIME ExitTime     = {0};
  FILETIME KernelTime   = {0};
  FILETIME UserTime     = {0};

  // try to get the times
  if(GetProcessTimes(
      hProcess,
      &CreationTime,
      &ExitTime,
      &KernelTime,
      &UserTime
  )){
    // succeeded, the times are now in the respective FILETIMEs
    cout  <<  "GetProcessTimes() succeeded!\n"
              "Todo: figure out the seconds that this process has\n"
              "spent in user and in kernel mode.\n";
  }
  else {
    cout << "GetProcessTimes() failed, error: " 
          << GetLastError() << endl;
  }

  // clean up
  CloseHandle(hProcess);

  return 0;
}

GetProcessTimes() documented -> GetProcessTimes()
OpenProcess() documented -> OpenProcess()

About these FILETIME structures that are used ...

All times are expressed using FILETIME data structures. Such a structure contains two 32-bit values that combine to form a 64-bit count of 100-nanosecond time units.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.