Skip to content

Instantly share code, notes, and snippets.

@gusennan
Last active November 27, 2015 16:47

Revisions

  1. gusennan revised this gist Nov 27, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions perf-test.cpp
    Original file line number Diff line number Diff line change
    @@ -32,3 +32,7 @@ double hamiltonianValue(int i, int j, double currentTime, double totalTime, doub
    }
    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){ ...
  2. gusennan revised this gist Nov 27, 2015. 1 changed file with 24 additions and 3 deletions.
    27 changes: 24 additions & 3 deletions perf-test.cpp
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,4 @@
    (1a)

    //takes in two "points" (arrays of doubles), and returns an array of doubles that contains
    //the slope and the y intercept of the line between the two points
    double * line(double * pt1, double * pt2){
    double xTmp, yTmp;
    xTmp = (pt2[1]-pt1[1])/(pt2[0]-pt1[0]);
    @@ -11,3 +8,27 @@ double * line(double * pt1, double * pt2){
    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;
    }
  3. gusennan created this gist Nov 27, 2015.
    13 changes: 13 additions & 0 deletions perf-test.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    (1a)

    //takes in two "points" (arrays of doubles), and returns an array of doubles that contains
    //the slope and the y intercept of the line between the two points
    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;
    }