/*
* Jesse B. Dooley
* Date: April 27, 2000
* For: CMSC 420-0201 Spring 2000
* Prof. Michelle Hugue
* Title: Project 2 Shortest Maintenance Paths
* Module: route.cc
*/
#ifndef ROUTE_CC
#define ROUTE_CC
#include <stdlib.h>
#include <cmath>
#include <iostream.h>
#include "TemasBase.h"
#include "weight.cc"
#include "site.cc"
#include <string>
using namespace std;
class route {
site* start_site_p; // lesser name
site* finish_site_p; // greater name
weight route_weight; // distance between sites
void calcroute()
{
// The formula for point distance is:
// square root of
// (x2 - x1)^2 + (y2 - y1)^2
// where (x1,x2) and (y1,y2) are points on an xy plane.
if( start_site_p == NULL ||
finish_site_p == NULL )
return;
float Xdiff = DBL_MAX;
float Ydiff = DBL_MAX;
Xdiff = finish_site_p->xaxis() - start_site_p->xaxis();
Ydiff = finish_site_p->yaxis() - start_site_p->yaxis();
Xdiff *= Xdiff;
Ydiff *= Ydiff;
route_weight.setweight( sqrt( Xdiff + Ydiff ) );
} // calcroute
public:
route()
{
start_site_p = NULL;
finish_site_p = NULL;
} // Route
route( const route &R )
{
start_site_p = R.start_site_p;
finish_site_p = R.finish_site_p;
route_weight = R.route_weight;
} // Route( Route R )
~route(){}
void erase()
{
start_site_p = NULL;
finish_site_p = NULL;
route_weight.setweight( DBL_MAX );
}
void make( site* S, site* F )
{
start_site_p = S;
finish_site_p = F;
calcroute();
}
string StartName()
{
return start_site_p->name();
}
site* StartSite()
{
return start_site_p;
}
site* FinishSite()
{
return finish_site_p;
}
string FinishName()
{
return finish_site_p->name();
}
weight RouteWeight()
{
return route_weight;
}
double getweight()
{
return route_weight.getweight();
}
void setweight( double D )
{
route_weight.setweight( D );
}
// overloads
bool operator==( const route &E )
{
return (start_site_p == E.start_site_p &&
finish_site_p == E.finish_site_p );
} // ==
bool operator==( const float D )
{
return (route_weight == D );
} // ==
bool operator==( const weight D )
{
return (route_weight == D );
} // ==
void operator=( const route &E )
{
start_site_p = E.start_site_p;
finish_site_p = E.finish_site_p;
route_weight = E.route_weight;
} // =
bool operator!=( const route &E )
{
return ( start_site_p != E.start_site_p );// && ( finish_site_p != E.finish_site_p ));
} // !=
bool operator!=( const weight &E )
{
return ( route_weight != E );
} // !=
bool operator<( const route &E )
{
return (start_site_p->name() < E.start_site_p->name() ||
(start_site_p->name() <= E.start_site_p->name() &&
finish_site_p->name() < E.finish_site_p->name() ));
} // <
bool operator<( const weight &E )
{
return ( route_weight < E );
} // <
bool operator>( const route &E )
{
return (start_site_p->name() > E.start_site_p->name() ||
(start_site_p->name() >= E.start_site_p->name() &&
finish_site_p->name() > E.finish_site_p->name()));
} // >
bool operator>( const weight &E )
{
return ( route_weight > E );
} // >
void OutPut()
{
cout << start_site_p->name();
cout << " <--> ";
cout << finish_site_p->name();
cout << " with length ";
route_weight.OutPut();
}
};
#endif // route.cc