void ExpandGivenMatch()
{
int V1index = (int)OldIndexOfV1.ToArray(typeof(int));
int V2index = (int)OldIndexOfV2.ToArray(typeof(int));
for (int i = 0; i < V1index.Length - 1; i++)
{
GivenMatch[V1index[i], V2index[i]] = 1;
GivenMatch[V1index[i + 1], V2index[i]] = 0;
}// for i
if (V2index.Length == V1index.Length)
{
int i = V2index.Length - 1;
GivenMatch[V1index[i], V2index[i]] = 1;
}
}
void MaxMatching()
{
bool boolfull = false;
bool boolhaveexpanded = true;
bool booladdx = true;
while (boolhaveexpanded == true)
{
boolhaveexpanded = false;
booladdx = true;
boolfull = boolDataFull();
if (boolfull == true)
{
return;
}
else
{
for (int i = 0; i < cn; i++)
{
SequencedIndexOfV2[i] = 0;
this.TV1[i] = 0;
}
OldIndexOfV1.Clear();
OldIndexOfV2.Clear();
int notfullindexofx = SearchNotFullIndexOfX();
ExpandOldIndexOfV1(notfullindexofx);
while (booladdx == true)
{
booladdx = false;
bool boolequal = IsTV1EqualV2(this.TV1, SequencedIndexOfV2);
if (boolequal == true)
{
return;
}
else
{
int iy = InTV1NotInV2(this.TV1, SequencedIndexOfV2);
ExpandOldIndexOfV2(iy);
int ix = IndexOfXMakeYFull(iy);
if (ix != -1)
{
ExpandOldIndexOfV1(ix);
booladdx = true;
boolhaveexpanded = true;
}
else
{
ExpandGivenMatch();
boolhaveexpanded = true;
//break;
}
}
}//while booladdx == true
}//if boolfull == true
}//while boolhaveexpanded == true
//showdata();
}
#region Check the Array''s values
void Checked()
{
if (OriginData.GetLength(0) != GivenMatch.GetLength(0))
{
throw new Exception("The first dimension of " + OriginData +
" should be equal to the first dinesion of" + GivenMatch);
}
if (OriginData.GetLength(1) != GivenMatch.GetLength(1))
{
throw new Exception("The first dimension of " + OriginData +
" should be equal to the first dinesion of" + GivenMatch);
}
for (int i = 0; i < OriginData.GetLength(0); i++)
{
for (int j = 0; j < OriginData.GetLength(1); j++)
{
if (OriginData[i, j] > 1 || OriginData[i, j] < -1)
{
throw new Exception("Each value of " + OriginData +
" must be -1 or 0 or 1 ");
}
if (GivenMatch[i, j] > 1 || GivenMatch[i, j] < -1)
{
throw new Exception("Each value of " + GivenMatch +
" must be -1 or 0 or 1 ");
}
}
}
}
#endregion
public int[,] resultArray()
{
Checked();
MaxMatching();
return GivenMatch;
}
}
}