Overview
Comment:Fixed presentation of globally optimised equations (ode view).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/global-optimisation | trunk
Files: files | file ages | folders
SHA3-256: 9b1fb2c9a9919f0fcb372eccfa737894b34128d83b4c914dcd6731538bebdee1
User & Date: geraint@users.sourceforge.net on 2002-09-10 22:09:14
Other Links: branch diff | manifest | tags
Context
2002-09-10
23:24:19
Rationalised local and global optimisations.
Fixes presentation of locally optimised code (ode view).
Much more elegant :-)
check-in: e5dbca659d user: geraint@users.sourceforge.net tags: origin/global-optimisation, trunk
22:09:14
Fixed presentation of globally optimised equations (ode view). check-in: 9b1fb2c9a9 user: geraint@users.sourceforge.net tags: origin/global-optimisation, trunk
2002-09-05
11:47:09
Does not now attempt optimisation if matrix has zero length.
Declaration of matrix size is left to def.r.
check-in: a3d8883875 user: geraint@users.sourceforge.net tags: origin/global-optimisation, trunk
Changes

Modified mttroot/mtt/bin/trans/def2write_r from [31e9ce13cc] to [f2349eb5aa].

9
10
11
12
13
14
15



16
17
18
19
20
21
22
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25







+
+
+







# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.16.2.1  2002/09/03 23:44:43  geraint
## adding global optimisation (-optg).
##
## Revision 1.16  2002/09/03 19:34:15  geraint
## Write EdX regardless - csex is needed to create ode when not optimised.
##
## Revision 1.15  2002/08/29 15:45:20  geraint
## Tests for existence of matrix before entering shell loop.
## Tests for existence of expression before attempting to write or optimise.
##
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254







+















+



for matrix in $matrices; do
    matrix_exists=`grep -i MTT${matrix} ${sys}_dae.r | wc -l | gawk '{print $1}'`
    if [ "$matrix" = "EdX" -o $matrix_exists -gt 0 ]; then
	n=`first "$ns"`; ns=`rest "$ns"` 
	m=`first "$ms"`; ms=`rest "$ms"`
	is=`n2m 1 $n`; 
	js=`n2m 1 $m`; 
	echo "write \"% Begin Matrix MTT${matrix}\"$" >> $1_$2_write.r
	if [ $n -ge 1 ]; then
	    for i in $is; do
		for j in $js; do
		    if [ ${opt:-""} = "-optimise_local" ]; then
			name=`echo MTT$matrix'('$i','$j')'`
			mtt_optimise_local $1 "$comma$name" "$name"
			comma=''
		    else
			echo 'write'
			name=`echo MTT$matrix'('$i','$j')'`
			echo '  '$comma$name ':=' $name '$'
		    fi >> $1_$2_write.r
		done
	    done
	fi
	echo "write \"% End Matrix MTT${matrix}\"$" >> $1_$2_write.r
    fi
done
echo ';END;'                           >>$1_$2_write.r

Modified mttroot/mtt/bin/trans/mtt_optimise_global from [6fb956c743] to [2e6c7a680f].

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53






























54
55
56
57
58
59
60
61
62
63
64
65
66
67
68


69
70



71
72
73
33
34
35
36
37
38
39







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93


94
95
96
97
98
99







-
-
-
-
-
-
-







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















+
+
-
-
+
+
+



	counter=`expr $counter + 1`
    done
    command="$command INAME mtt_tmp"
else
    command=""
fi

# Generate matrix declaration
if [ $nmatrix -gt 0 ]; then
    matrix_declaration="matrix mtt$matrix($nmatrix,1)"
else
    matrix_declaration="matrix mtt$matrix"
fi

logfile=${system}_${representation}_global_optimisation.log
tmpfile=${system}_${representation}_global_optimisation.tmp
outfile=${system}_${representation}.r

if [ ! -f $outfile ]; then
    exit $E_FILE_NOT_EXIST
fi

find_code ()
{
    file_in=${1:-${IN}}
    portion=${2:-"body"}
    head=`cat ${file_in} | gawk '($2 == "Begin" && $3 == "Matrix") { print NR }'`
    foot=`cat ${file_in} | gawk '($2 == "End"   && $3 == "Matrix") { print NR }'`
    case ${portion} in
	head)
	    start=0
	    end=${head}
	    ;;
	body)
	    start=${head}
	    end=${foot}
	    ;;
	foot)
	    start=${foot}
	    end=end
	    ;;
	*)
	    echo "Error in find_code: portion unknown"
	    return -1
	    ;;
    esac
    cat ${file_in} |\
    gawk --assign start=${start} --assign end=${end} '
	(start < NR && NR < end) { print $0 }'
};


# Use Reduce to perform the optimisation
${SYMBOLIC:-reduce} <<EOF > $logfile 2>&1
off nat;
in "${system}_def.r";
in "$outfile";
load scope;
out "$tmpfile";
$command;
shut "$tmpfile";
$end;
EOF

cp $outfile $outfile.unoptimised
cp $tmpfile $outfile.tmp

find_code $outfile head > $tmpfile.head
cat $tmpfile | mtt_fix_integers > $outfile
#cp $tmpfile $outfile
cat $tmpfile | mtt_fix_integers > $tmpfile.body
find_code $outfile foot > $tmpfile.foot
cat $tmpfile.head $tmpfile.body $tmpfile.foot > $outfile
echo ";end;" >> $outfile

mtt_error_r $logfile


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]