For the answer you do not need to run the four heuristics and get the results. J
ID: 3602669 • Letter: F
Question
For the answer you do not need to run the four heuristics and get the results. Just tell me how to get the results or give me the code to do so.
randomLAP creates random 25 X 25 matrices with values in the range of 100 to 500. It's code looks like this:
# ------------------
import sys
from random import random
# default parameter values in case they aren't specified
# on the command line
fname = 'r.csv'
num = 25
min_val = 100
max_val = 500
# command line parameters
if len(sys.argv) > 1:
# asking for help?
if sys.argv[1] == '--help':
print 'Syntax: randomLAP [fname] [num min_val max_val]'
exit()
fname = sys.argv[1]
if len(sys.argv) == 5 :
try:
num = int(sys.argv[2])
min_val = float(sys.argv[3])
max_val = float(sys.argv[4])
except:
print 'Invalid parameters. Syntax: randomLP.py fname num min_val max_val'
exit()
val_range = max_val - min_val
matrix = []
# generate the random values - use U(min_val, max_val)
for k in range(num):
matrix.append([])
for j in range(num):
matrix[k].append(min_val + (random() * val_range))
# write the file
with open(fname, 'w') as outfile:
for k in range(num):
row = ['{:.2f}'.format(x) for x in matrix[k]]
outfile.write('{} '.format(', '.join(row)))
# print information
print ' Created a {}x{} cost matrix with values in the range {} - {}. File: {} '.format(
num, num, min_val, max_val, fname
)
Explanation / Answer
#include <stdio.h>
int main()
{
printf("Hello, World! I have created a dynamic 2D-array of 20x30 integers! ");
int i,j,k,arr[20][30];
k = 0;
for(i=0 ; i<20 ; i++)
{
k = i;
for(j=0 ; j<30 ; j++)
{
arr[i][j] = k;
printf("%d ",k);
k++;
}
printf(" ");
}
return 0;
}
=============> OUTPUT <=================
Hello, World! I have created a dynamic 2D-array of 20x30 integers!
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48