1 /**
2 * @file arrays_example3.cpp
3 * @brief arrays create example
4 * @author Sarah Keating
5 *
6 * <!--------------------------------------------------------------------------
7 * This file is part of libSBML. Please visit http://sbml.org for more
8 * information about SBML, and the latest version of libSBML.
9 *
10 * Copyright (C) 2009-2013 jointly by the following organizations:
11 * 1. California Institute of Technology, Pasadena, CA, USA
12 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
13 *
14 * Copyright (C) 2006-2008 by the California Institute of Technology,
15 * Pasadena, CA, USA
16 *
17 * Copyright (C) 2002-2005 jointly by the following organizations:
18 * 1. California Institute of Technology, Pasadena, CA, USA
19 * 2. Japan Science and Technology Agency, Japan
20 *
21 * This library is free software; you can redistribute it and/or modify it
22 * under the terms of the GNU Lesser General Public License as published by
23 * the Free Software Foundation. A copy of the license agreement is provided
24 * in the file named "LICENSE.txt" included with this software distribution
25 * and also available online as http://sbml.org/software/libsbml/license.html
26 * ------------------------------------------------------------------------ -->
27 */
28
29 #include <sbml/SBMLTypes.h>
30 #include <sbml/packages/arrays/common/ArraysExtensionTypes.h>
31
32
33 using namespace std;
34 LIBSBML_CPP_NAMESPACE_USE
35
36 int
main(int argc,char * argv[])37 main (int argc, char* argv[])
38 {
39 SBMLNamespaces sbmlns(3,1,"arrays",1);
40
41 // create the document
42
43 SBMLDocument *document = new SBMLDocument(&sbmlns);
44
45 // set the required attribute to true
46 ArraysSBMLDocumentPlugin * docPlug =
47 static_cast<ArraysSBMLDocumentPlugin*>(document->getPlugin("arrays"));
48 docPlug->setRequired(true);
49
50
51 // create the Model
52
53 Model* model=document->createModel();
54
55 // create the parameters
56
57 // first parameter - for dimension m
58 Parameter * p = model->createParameter();
59 p->setId("m");
60 p->setConstant(true);
61 p->setValue(2);
62
63 // second parameter - for dimension n
64 p = model->createParameter();
65 p->setId("n");
66 p->setConstant(true);
67 p->setValue(1);
68
69 // third parameter - 2 x 1 matrix of parameters
70 p = model->createParameter();
71 p->setId("x");
72 p->setConstant(false);
73
74
75 // create the Dimensions via the Plugin
76 ArraysSBasePlugin * arraysPlug =
77 static_cast<ArraysSBasePlugin*>(p->getPlugin("arrays"));
78
79 // first dimension
80 Dimension * dim = arraysPlug->createDimension();
81 dim->setArrayDimension(0);
82 dim->setSize("m");
83
84 // second dimension
85 dim = arraysPlug->createDimension();
86 dim->setArrayDimension(1);
87 dim->setSize("n");
88
89 // other parameters
90 p = model->createParameter();
91 p->setId("y");
92 p->setConstant(true);
93 p->setValue(2.3);
94
95
96
97 // create the initialAssignment
98 InitialAssignment *ia = model->createInitialAssignment();
99 ia->setSymbol("x");
100
101 ASTNode * row1 = new ASTNode(AST_LINEAR_ALGEBRA_VECTOR);
102
103 ASTNode * ci1 = new ASTNode(AST_NAME);
104 ci1->setName("y");
105
106 row1->addChild(ci1);
107
108 ASTNode * row2 = new ASTNode(AST_LINEAR_ALGEBRA_VECTOR);
109
110 ASTNode * ci2 = new ASTNode(AST_INTEGER);
111 ci2->setValue(2);
112
113 row2->addChild(ci2);
114
115 ASTNode * math = new ASTNode(AST_LINEAR_ALGEBRA_VECTOR);
116
117 math->addChild(row1);
118 math->addChild(row2);
119
120 ia->setMath(math);
121
122 writeSBML(document,"arrays_example3.xml");
123
124 delete document;
125
126 return 0;
127 }
128