Information Technology Reference
In-Depth Information
constraints explicitly, so that the reader may check that we have set this up correctly.
Before showing the actual code we first outline the process.
Outline of detMin
detMin
1. Input: the dimension, and the parameter settings we will use for NMinimize .
2. Create a matrix of variables.
3. Create a set of constraints.
All variables must be integers.
All variables lie in the range [
1 , 1].
Variables corresponding to the diagonal elements are all set to 1.
4. Call NMinimize on the objective function, using the above constraints and
taking program parameters from the argument list.
5. Return the optimum found by NMinimize , along with the matrix that gives
this value.
Here is the actual program to do this.
detMin[n , cp , sp , it , printsetup :False]:=Module[
detMin[n , cp , sp , it , printsetup :False]:=Module[
detMin[n , cp , sp , it , printsetup :False]:=Module[
{
{
{
mat , vars , problemlist , j , best
mat , vars , problemlist , j , best
mat , vars , problemlist , j , best
}
}
}
,
,
,
mat = Array[ x ,
mat = Array[ x ,
mat = Array[ x ,
{
{
{
n , n
n , n
n , n
}
}
}
];
];
];
vars = Flatten[mat];
vars = Flatten[mat];
problemlist =
problemlist =
problemlist =
{
{
{
detfunc[mat] , Flatten[
detfunc[mat] , Flatten[
detfunc[mat] , Flatten[
{
{
{
Element[vars , Integers] , Map[
Element[vars , Integers] , Map[
Element[vars , Integers] , Map[
1
1
1
#
#
#
1& , vars] ,
1& , vars] ,
1& , vars] ,
;
If[printsetup , Print[problemlist[[2]]]];
Tab le[ x [ j , j ]==1 ,
Tab le[ x [ j , j ]==1 ,
Tab le[ x [ j , j ]==1 ,
{
{
{
j , n
j , n
j , n
}
}
}
]
]
]
}
}
}
]
]
]
}
}
}
;
;
If[printsetup , Print[problemlist[[2]]]];
best = NMinimize[problemlist , vars , MaxIterations
If[printsetup , Print[problemlist[[2]]]];
best = NMinimize[problemlist , vars , MaxIterations
best = NMinimize[problemlist , vars , MaxIterations
it ,
it ,
it ,
Method
Method
Method
→{
→{
→{
DifferentialEvolution , CrossProbability
DifferentialEvolution , CrossProbability
DifferentialEvolution , CrossProbability
cp , SearchPoints
cp , SearchPoints
cp , SearchPoints
sp
sp
sp
}
}
}
];
];
];
{
{
{
best[[1]] , mat/.best[[2]]
best[[1]] , mat/.best[[2]]
best[[1]] , mat/.best[[2]]
}
}
}
]
Here is our result for three-by-three matrices. We also show the constraints for this
small example.
Timing[
Timing[
Timing[
{
{
{
min , mat
min , mat
min , mat
}
}
}
= detMin[3 ,. 1 , 20 , 20 , True]]
= detMin[3 ,. 1 , 20 , 20 , True]]
= detMin[3 ,. 1 , 20 , 20 , True]]
{
( x [1 , 1]
|
x [1 , 2]
|
x [1 , 3]
|
x [2 , 1]
|
x [2 , 2]
|
x [2 , 3]
|
x [3 , 1]
|
x [3 , 2]
|
x [3 , 3])
Integers ,
1
x [1 , 1]
1 ,
1
x [1 , 2]
1 ,
1
x [1 , 3]
1 ,
1
x [2 , 1]
1 ,
1
x [2 , 2]
1 ,
1
x [2 , 3]
1 ,
1
x [3 , 1]
1 ,
1
x [3 , 2]
1 ,
1
x [3 , 3]
1 ,
x [1 , 1]==1 , x [2 , 2]==1 , x [3 , 3]==1
}
{
0 . 528033 ,
{−
4 .,
{{
1 , 1 , 1
}
,
{
1 , 1 ,
1
}
,
{
1 ,
1 , 1
}}}}
Search WWH ::




Custom Search