Skip to content

Instantly share code, notes, and snippets.

@gusennan
Last active November 27, 2015 16:47
Show Gist options
  • Save gusennan/c98dfb664effce04d77d to your computer and use it in GitHub Desktop.
Save gusennan/c98dfb664effce04d77d to your computer and use it in GitHub Desktop.
(1a)
double * line(double * pt1, double * pt2){
double xTmp, yTmp;
xTmp = (pt2[1]-pt1[1])/(pt2[0]-pt1[0]);
yTmp = pt1[1] - xTmp*pt1[0];
pt1[0] = xTmp;
pt1[1] = yTmp;
return pt1;
}
(1b)
double hamiltonianValue(int i, int j, double currentTime, double totalTime, double* hp, double * schedule){
double value=0;
double progValue = 0;
double numPoints =schedule[0];
double pt1[2];
double pt2[2];
int interval = findInterval(currentTime, totalTime, numPoints);
pt1[0] = ((double)interval-1.0)*(1/numPoints);
pt1[1] = schedule[interval];
pt2[0] = (double)interval*(1/numPoints);
pt2[1] = schedule[interval+1];
double * line1 = line(pt1, pt2);
progValue = line1[0] * (currentTime/totalTime) + line1[1];
if(i == j){
value = hp[i] * progValue;
return value;
}
else {
if(neighbor((unsigned char) i ,(unsigned char)j))
return -1.0*(1.0-progValue);
}
return 0;
}
(2a) inline int findInterval(double currentTime, double totalTime, double numIntervals) { ...
(2b) inline double * line(double * pt1, double * pt2){ ...
(2c) inline bool neighbor(unsigned char i, unsigned char j){ ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment