# *  --------------------------------------------------------------------------  *
#  * A Monte Carlo simulation of a stochastic activity network.                  *
#  *                                                                             *
#  * Name              : san.c                                                   *
#  * Author            : Jeff Mallozzi, Kerry Connell, Larry Leemis, Matt Duggan *
#  * Language          : ANSI C                                                  *
#  * Latest Revision   : 6-16-04                                                 *
#  # Translated by   : Philip Steele 
#  # Language        : Python 3.3
#  # Latest Revision : 3/26/14                                    *
#  ----------------------------------------------------------------------------- */


from math import sqrt, log, exp
from rngs import random, putSeed

MAXEDGE = 50
MAXNODE = 50
MAXPATHS = 50
N = 10000                           # number of replications */

M = [[None for i in range(0,MAXEDGE)] for i in range(0,MAXNODE)]
Paths = [[None for i in range(0,MAXEDGE)] for i in range(0,MAXPATHS)]
UpperLimit = [None for i in range(0,MAXEDGE)]
p = [None for i in range(0,MAXEDGE)]
paths = None
nodes = None
edges = None

def Uniform(a,b):  
#  ---------------------------------------------
# * generate a Uniform random variate, use a < b 
# *--------------------------------------------- 
# */
  return (a + (b - a) * random())  

# ========================== */
def GetActivityDurations():
# ========================== */
  for i in range(1,edges+1):
    p[i] = Uniform(0.0, UpperLimit[i])

  return()

# ================ */
def PrintPaths():
# ================ */
  print("")
  for i in range(1,paths+1):
    print("Path {0:1d}: ".format(i), end='')
    j = 1
    while(Paths[i][j] != 0):
      j += 1
    #EndWhile
    j -= 1
    while(j > 0):
      print("-{0:1d}-".format(Paths[i][j]), end='')
      j -= 1
    #EndWhile
    print("")