<?xml version="1.0" encoding="UTF-8"?>
<osil xmlns="os.optimizationservices.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="os.optimizationservices.org http://www.optimizationservices.org/schemas/OSiL.xsd">
	<instanceHeader>
		<name>sample illustration of matrix programming</name>
		<source>Jun Ma</source>
		<description><![CDATA[
			Given 4 scalar variables (x0-x3) and 1 scalar constraint (c0) and 2 matrix constraints (C0, C1). 
			Given matrixVar X0 as
			[x0, x1
			 x2, x3]
			Given matrixVar X1 as
			[x0, x1
			 x3, x2]
			Given numberMatrices M2, M3, M4, M5, M6 (they have a corresponding matrix id in OSiL; also note the various ways of constructing them)

		        minimize 3x3 +sin(x1) + trace(C4'X0)+elementSum(X1'C5) + det(C6X0'*X1)
				subject to 
	                        //scalar constraints and bounds
				-4 <= c2 <= 4, where c2 = 2.2x0+3.3x1 + 4.4x0x1+ cos(x2) 			
				-3 <= x2 <= 3 	
				//matrix variable bound
				M3 <= X1 <= M4 (in the positive semidefinite sense
	                    //matrix constraints and bounds					
				C0 : M3 <= 1/2*M5X0M6'+1/2*M6X0M5'+ M6*(X1M5')+2.0*M6 <= M4  
				       1/2*M5X0M6'+1/2*M6X0M5'+ M6*(X1M5')+2.0*M6 - M3 is contained in a Lorentz cone
				       M4 - 1/2*M5X0M6'+1/2*M6X0M5'+ M6*(X1M5')+2.0*M6 is contained in a distorted normed cone
				C1: M5 <= M3X0M4'+ diag(M4X1M3') +Inverse(M3) <= M6
	                  M3X0M4'+ diag(M4X1M3') +Inverse(M3) - M5 is a copositive matrix
	                  M6 - M3X0M4'+ diag(M4X1M3') +Inverse(M3) is contained in a product cone
	
				X0 positiveSemidefinite with nonnegative entries
		]]></description>
	</instanceHeader>
	<instanceData>
		<variables numberOfVariables="4">
			<var name="x0" lb="-INF" ub="INF" type="C"/>
			<var name="x1" lb="-INF" ub="INF" type="C"/>
			<var name="x2" lb="-INF" ub="INF" type="C"/>
			<var name="x3" lb="-3" ub="3" type="C"/>
		</variables>
		<objectives numberOfObjectives="1">
			<obj maxOrMin="min" numberOfObjCoef="1">
				<coef idx="3">3</coef>
			</obj>
		</objectives>
		<constraints numberOfConstraints="1">
			<con name="c0" lb="-4" ub="4"/>
		</constraints>
		<linearConstraintCoefficients numberOfValues="2">
			<start>
				<el>0</el>
				<el>2</el>
			</start>
			<colIdx>
				<el>0</el>
				<el>1</el>
			</colIdx>
			<value>
				<el>2.2</el>
				<el>3.3</el>
			</value>
		</linearConstraintCoefficients>
		<quadraticCoefficients numberOfQuadraticTerms="1">
			<qTerm idx="0" idxOne="0" idxTwo="1" coef="4.4"/>
		</quadraticCoefficients>
		<nonlinearExpressions numberOfNonlinearExpressions="3">
			<nl idx="-1">
				<sin>
					<variable idx="1"/>
				</sin>
			</nl>
			<nl idx="-1">
				<matrixDeterminant>
					<matrixTimes>
						<matrix id="6"/>
						<matrixTimes>
							<matrixVariable idx="0"/>
							<matrixVariable idx="1"/>
						</matrixTimes>
					</matrixTimes>
				</matrixDeterminant>
			</nl>
			<nl idx="0">
				<cos>
					<variable idx="2"/>
				</cos>
			</nl>
		</nonlinearExpressions>
		<matrices numberOfMatrices="9">
			<constantMatrix id="M2" numberOfRows="2" numberOfColumns="2">
				<elements numberOfValues="4">
					<start>
						<el>0</el>
						<el>2</el>
						<el>4</el>
					</start>
					<colIdx>
						<el>0</el>
						<el>1</el>
						<el>0</el>
						<el>1</el>
					</colIdx>
					<value>
						<el>21</el>
						<el>22</el>
						<el>23</el>
						<el>24</el>
					</value>
				</elements>
			</constantMatrix>
			<constantMatrix id="M3" numberOfRows="2" numberOfColumns="2">
				<elements numberOfValues="1" base="matrix" baseMatrixID="M2">
					<start>
						<el>0</el>
						<el>1</el>
					</start>
					<colIdx>
						<el>1</el>
					</colIdx>
					<value>
						<el>31</el>
					</value>
				</elements>
			</constantMatrix>
			<constantMatrix id="M4" numberOfRows="2" numberOfColumns="2">
				<elements numberOfValues="4">
					<start>
						<el>0</el>
						<el>2</el>
						<el>4</el>
					</start>
					<colIdx>
						<el>0</el>
						<el>1</el>
						<el>0</el>
						<el>1</el>
					</colIdx>
					<value>
						<el>41</el>
						<el>42</el>
						<el>43</el>
						<el>44</el>
					</value>
				</elements>
			</constantMatrix>
			<constantMatrix id="M5" numberOfRows="2" numberOfColumns="2">
				<elements numberOfValues="0" base="matrix" baseMatrixID="M4" baseMatrixStartRow="0" baseMatrixEndRow="0" baseMatrixStartCol="0" baseMatrixEndCol="1"/>
			</constantMatrix>
			<!--
					Mest1
						[41, 42]
				-->
			<constantMatrix id="MTest1" numberOfRows="1" numberOfColumns="2">
				<elements numberOfValues="0" base="matrix" baseMatrixID="M4" baseMatrixStartRow="0" baseMatrixEndRow="0" baseMatrixStartCol="0" baseMatrixEndCol="1" baseTranspose="true"/>
			</constantMatrix>
			<constantMatrix id="MTest2" numberOfRows="2" numberOfColumns="2">
				<transformation>
					<matrixPower>
						<matrixTimes>
							<matrix id="M3"/>
							<matrix id="M4"/>
						</matrixTimes>
						<number value="2"/>
					</matrixPower>
				</transformation>
			</constantMatrix>
			<linearMatrix id="XBase" numberOfRows="2" numberOfColumns="2" numberOfEl="0" varIdxStart="0" varIdxEnd="3" rowMajor="true"/>
			<linearMatrix id="X0" base="matrix" baseMatrixID="XBase" numberOfRows="2" numberOfColumns="2" numberOfEl="0"/>
			<linearMatrix id="X1" base="matrix" baseMatrixID="XBase" numberOfRows="2" numberOfColumns="2" numberOfEl="2">
				<el rowIdx="1" colIdx="0" varIdx="3"/>
				<el rowIdx="1" colIdx="1" varIdx="2"/>
			</linearMatrix>
			<linearMatrix id="XTest" base="matrix" baseMatrixID="XBase" numberOfRows="2" numberOfColumns="2" numberOfEl="4">
				<!--
					XTest
						[x3, 2.0*x2+3.0
			 			5.0, 1.0*x1+2.0*X2+4.0]
				-->
				<el rowIdx="0" colIdx="0" varIdx="3"/>
				<el rowIdx="1" colIdx="1" scalarCoef="2.0" constant="3.0" varIdx="2"/>
				<el rowIdx="1" colIdx="0" constant="5.0"/>
				<el rowIdx="1" colIdx="1" constant="4.0">
					<var idx="1" coef="2.0"/>
					<var idx="2" coef="4.0"/>
				</el>
			</linearMatrix>
			<generalMatrix id="M6" numberOfRows="2" numberOfColumns="2" numberOfEl="1" base="matrix" baseTranspose="true" baseMatrixID="M5">
				<el rowIdx="0" colIdx="1">
					<matrixDeterminant>
						<matrix id="5"/>
					</matrixDeterminant>
				</el>
			</generalMatrix>
		</matrices>
		<cones numberOfCones="8">
			<nonnegativeCone numberOfRows="2" numberOfCols="2" id="C0"/>
			<semidefiniteCone numberOfColumns="2" numberOfRows="2" type="positiveDefinite" id="C1"/>
			<intersectionCone numberOfColumns="2" numberOfRows="2" numberOfCones="2" id="C2">
				<cone coneId="C0"/>
				<cone coneId="C1"/>
			</intersectionCone>
			<quadraticCone numberOfRows="2" numberOfCols="2" id="C3"/>
			<normedCone numberOfRows="2" numberOfCols="2" pNorm="INF" distortionMatrixId="M10" id="C4"/>
			<copositiveMatricesCone numberOfColumns="2" numberOfRows="2" id="C5"/>
			<generalOrthantCone numberOfRows="1" numberOfCols="2" id="C6">
				<direction ub="INF" lb="0.0"/>
				<direction ub="0.0" lb="-INF"/>
			</generalOrthantCone>
			<productCone numberOfColumns="2" numberOfRows="2" numberOfFactors="2" id="C7">
				<factor coneId="C6"/>
				<factor coneId="C6"/>
			</productCone>
		</cones>
		<matrixProgramming>
			<matrixVariables numberOfMatrixVariables="2">
				<matrixVar matrixID="X0" lbConeId="C2"/>
				<matrixVar matrixID="X1" lbMatrixID="M3" lbConeId="C1" ubMatrixID="M4" ubConeId="C1"/>
			</matrixVariables>
			<objectives>
				<obj objIdx="-1" numberOfObjLinearMatrixOperators="2">
					<linearMatrixOperator termOperator="trace" matrixVarIdx="0" leftMatrixID="M4" leftMatrixTranspose="true"/>
					<linearMatrixOperator termOperator="elementSum" matrixVarIdx="1" matrixVarTranspose="true" rightMatrixID="M5"/>
				</obj>
			</objectives>
			<matrixConstraints numberOfMatrixConstraints="2">
				<matrixCon numberOfRows="2" numberOfCols="2" constantMatrixID="M6" constantMatrixScalarCoef="2.0" lbMatrixID="M3" lbConeId="C3" ubMatrixID="M4" ubConeId="C4" positiveSemidefinite="true"/>
				<matrixCon numberOfRows="2" numberOfCols="2" lbMatrixID="M5" lbConeId="C5" ubMatrixID="M6" ubConeId="C7"/>
			</matrixConstraints>
			<linearConstraintMatrixOperators numberOfMatrixOperators="5">
				<operator matrixConIdx="0" matrixVarIdx="0" scalarCoef="0.5" leftMatrixID="M5" rightMatrixID="M6" rightMatrixTranspose="true" leftOperator="matrixProduct" leftOperatorFirst="true"/>
				<operator matrixConIdx="0" matrixVarIdx="0" scalarCoef="0.5" leftMatrixID="M6" rightMatrixID="M5" rightMatrixTranspose="true"/>
				<operator matrixConIdx="0" matrixVarIdx="1" leftMatrixID="M6" rightMatrixID="M5" rightMatrixTranspose="true" leftOperatorFirst="false"/>
				<operator matrixConIdx="1" matrixVarIdx="0" leftMatrixID="M3" rightMatrixID="M4" rightMatrixTranspose="true"/>
				<operator matrixConIdx="1" matrixVarIdx="1" leftMatrixID="M4" rightMatrixID="M3" rightMatrixTranspose="true" termOperator="diagonal"/>
			</linearConstraintMatrixOperators>
			<nonlinearMatrixExpressions numberOfMatrixNonlinearExpressions="1">
				<matrixNL matrixConIdx="1">
					<matrixInverse>
						<matrix id="3"/>
					</matrixInverse>
				</matrixNL>
			</nonlinearMatrixExpressions>
		</matrixProgramming>
	</instanceData>
</osil>
