Вы находитесь на странице: 1из 56

Ludmila Naumova

NP=P? Algorithms
for solving NP-problems
by matrix method
in Scilab program

Издательские решения
Under license from Ridero
2018
Fonts by «ParaType»

© Ludmila Naumova, 2018


ISBN 978-5-4493-7302-1
Created with Ridero smart publishing system
CONTENTS
Introduction 5
Chapter 1. The essence of the method; commands and typical
algorithms in the program Scilab 6.0.1 7
— The essence of the method 7
— NP-problems and their models in small numbers,
General algorithms 8
— Specify the source data 9
— Permutations 9
— Permutations followed by matrix replacement and
finding solutions 10
— Placements 14
— Fulfillment of additional conditions in the task 14
— Complex placements 15
— Solving the problems of combinations and arrangements
with the help of zeros in the rows of the original matrix 17
— Combinations 19
Chapter 2. Detailed solution of problems in the program
Scilab 6.0.1 21
2.1. Model-problem №1 21
2.2. Task-model №1—1 38
2.3. Task-model №2 48
CONCLUSION 51
INTRODUCTION
From the course of school mathematics, we all know the prob-
lems of combinatorics, such as the problem of permutations, com-
binations, placement, represented by the corresponding formulas.
But these formulas only give us the number of solutions, not the
solutions themselves. There were no common standard algorithms
for solving these types of problems. These types of problems with
large numbers can be referred to NP problems. But with the help
of Scilab program typical algorithms of such problems are re-
vealed and solutions are given, and not only the number of solu-
tions. The essence of the algorithms consists in operating with el-
ements of natural series in rows and columns of the matrix, as
well as in operating with rows and columns of the matrix using
Scilab’s commands. NP-problems, in principle, represent all the
same combinatorics problems, but in large numbers. So in one NP-
problem can be present immediately as permutations and combi-
nations and placement, can be these operations (combinations,
placement, permutations) sequentially repeated, but with other,
obtained in the course of solving the problem, data, can be set ad-
ditional or any other conditions or calculations. The bottom line is
that knowing the typical algorithms of permutations, placement,
combinations, these algorithms can be used as much as necessary
in a single problem and thus solve NP problems. Let us emphasize
once again that the algorithms below give the solutions them-
selves, not just answers about the number of solutions, although
they also give. In large numbers, the solution of these problems
requires a large resolution power of the computer, but the algo-
rithms remain the same. This book provides examples with small
numbers, but the point remains the same. Thus, the author wants
to show that often the solution of the problem lies on the surface,
but sometimes we can not see the solution at this angle. The au-

5
LUDMILA NAUMOVA

thor is confident that more and more NP-problems will move into
the category of P — problems. This process is inevitable with the
development of programs and the growth of computer power.

6
CHAPTER 1. THE ESSENCE OF THE
METHOD; COMMANDS AND
TYPICAL ALGORITHMS IN THE
PROGRAM SCILAB 6.0.1

— THE ESSENCE OF THE METHOD

Any set can be written as a matrix with elements of this set.


The essence of the method used consists of operating on natural
numbers (elements of sets), applying a matrix approach, that is,
operating on elements of matrices, their columns and rows, as well
as in the interactions between matrices (sets).
Common algorithms for combinatorics problems, such as per-
mutation, combination, placement problems, which are given be-
low, are applicable for NP — problems. These types of problems
(on permutations, combinations, placements) with large numbers
can be attributed to NP — problems. NP-problems, in essence, rep-
resent all the same problems of combinatorics, but in a compli-
cated version, in one problem can be present immediately as per-
mutations and combinations and placement, these operations
(combinations, placement, permutations) can be repeated sequen-
tially, but with other data obtained in the course of solving the
problem, additional conditions or calculations can be set. But with
the help of Scilab program typical algorithms of such problems are
revealed and solutions are given, not only the number of solutions.
The bottom line is that knowing the typical algorithms of permu-
tations, placement, combinations, they can be used as many as
standard algorithms in one problem and thus solve NP — prob-
lems.

7
LUDMILA NAUMOVA

— NP-PROBLEMS AND THEIR MODELS IN SMALL


NUMBERS, GENERAL ALGORITHMS

Here are examples of NP-problems:


Task №1.
Suppose that you are organizing a group of four hundred Uni-
versity students. The number of places is limited, and only one
hundred students will get a place in the hostel. The situation is
complicated by the fact that the Dean has provided you with a list
of pairs of students who can’t live together, and asked that no pair
from this list did not get to the final version.
Task №2.
Is it true that among the numbers {-2, -3, 15, 14, 7, -10, …} are
there any such that their sum is 0?
Or else, for example: 50, 2, 47, 5, 21, 4, 78, 1. Problem: is it
possible to choose among these numbers such that their sum will
give 100?
Task №3.
You want to find the shortest path that passes exactly one
time through each of the six cities A, B.C. D. I. F. You are given
a matrix of distances between all pairs of cities,
Tasks like the above 3 examples seem unsolvable (so far no
one has been able to prove that some of them are actually as com-
plex as it seems, i.e. that there is really no way to get an answer
using a computer).

We make models of these problems in small numbers to find


an algorithm and solve these problems:
Task-model №1
Let’s say you’re hosting a group of 5 University students. The
number of places is limited, and only 3 students will get a place
in the hostel. The situation is complicated by the fact that the
Dean provided you with a list of students who can’t live together,
and asked that none of this list was not in the final version.
Problem-model №1—1

8
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

Let’s say you’re hosting a group of 9 University students. The


number of places is limited to 4 — 2 rooms for 2 people, and only
4 students will get a place in the hostel.
Find these solutions.

Task-model №3.
You want to find the shortest path that passes exactly once
through each of the four cities A, B. C. D.. You are given a matrix
of distances between all pairs of cities,

Solutions of NP-problems and their model problems are simi-


lar and have the same algorithms, solutions of model problems are
given below.

— SPECIFY THE SOURCE DATA

The initial data in the commands are given


by a vector (a single matrix), but it is also possible
by a two-dimensional matrix, several matrices,
etc. each object is assigned a serial number. For
example, we have 5 students:
Let’s give each student a number in order: 1. – first
student; 2. – 2nd student....etc to 5. As a one-
dimensional matrix n
Program start:
loading the source environment
— > n= [1 2 3 4 5]
n=
1. 2. 3. 4. 5.

— PERMUTATIONS

The permutation is performed using the perms (n) command:


Now we find all possible permutations from 1 to 5, there will
be 120. The answer will be written in the form of a matrix, where

9
LUDMILA NAUMOVA

each row is a variant of one of the permutations, the number


of rows in the matrix will be equal to the number of permutations,
and the number of columns will be equal to the originally speci-
fied elements (in our case 5).
— > P=perms (n)

— PERMUTATIONS FOLLOWED BY MATRIX


REPLACEMENT AND FINDING SOLUTIONS

As an example with a complex permutation (replacement


of the matrix obtained as a permutation to another matrix), the
problem-model №3:
You want to find the shortest path that passes exactly once
through each of the four cities A, B. C. D. You are given a matrix
of distances between all pairs of cities,
Decision.
The essence of the solution is that finding all the permutations
between the four cities in the form of rows of the matrix, replace
the rows of the resulting matrix with the rows of another matrix,
the elements of which are the distances between the cities and
calculate the paths, then find the smallest.
Set the initial conditions: cities A, B,C, D are numbered in or-
der and assign each city number 1,2,3,4, respectively. Let’s set the
distance between cities by matrices, for example. distance be-
tween town A and B as a matrix ab whose elements is a pair
of 1 and 2 (this is the number of cities A and B):
— > ab= [1 2];
— > ac= [1 3];
— > ad= [1 4];
— > ba= [2 1];
— > bc= [2 3];
— > bd= [2 4];
— > ca= [3 1];
— > cb= [3 2];
— > cd= [3 4];

10
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

— > da= [4 1];


— > db= [4 2];
— > dc= [4 3];
— > M= [1 2 3 4]
M=
— 2. 3. 4.
We find all possible permutations and obtain the matrix P.
— -> P=perms (M);
The result is a matrix of 4 columns (cities) and rows-variants
of permutations.
If in the condition of the problem it was necessary to return
back to the initial point, then to the matrix obtained as a result
of permutations it would be necessary to add another one column
where the element in each row would be the element of the first
row of the matrix P.
The program does not provide a command to replace the origi-
nal matrix, therows of which are the paths indicated by a sequen-
tial enumeration of cities, with a matrix of distances between
these cities (for example, such a command could be called com-
mand “between”. The value of command “between” the elements
with values 1 and 2 is 10, for example, as the initial data between
([1 2]) =10; insert values between the elements of the matrix rows
P as between (P:,1)). So we’ll have to go the other way. Divide the
resulting matrix P into 3 parts, and then connect again, as be-
tween 4 cities can build a path of three distances between cities.
These 3 matrices will consist: the 1st of the first two columns, the
2nd of the second and third columns, the 3rd of the third and
fourth columns.
— > N=P;
— > N (:,4) = [];
— > N (:,3) = [];
— > A=N;
— > X=P;
— > X (:,1) = [];
— > X (:,3) = [];

11
LUDMILA NAUMOVA

— > X (:,3) = [];


— > Q=P;
— > Q (:,1) = [];
— > Q (:,1) = [];
— > T=cat (2,A,X,Q);
Let’s create a matrix U, such that we replace the values of the
elements of the matrix T (that is, the numbers of cities) by the dis-
tances between them from the problem condition. For example,
in the line items written as [1 2 2 3 4] will be written as [ab bc cd].
— > U= [dc cb ba; dc ca ab; db bc ca; db ba ac; da ac cb; da ab
bc; cd db ba; cd da ab; cb bd da; cb ba ad;
ca ad db; ca ab bd; bd dc ca; bd da ac; bc ca ad; bc cd da; ba ad
dc; ba ac cd; ad dc cb; ad db bc; ac cd db;
ac cb bd; ab bd dc; ab bc cd];
The distances between cities are known to us by the problem
condition, let us set them and write down the matrix again:
— > ab= [10 0];
— > ac= [5 0];
— > ad= [4 0];
— > ba= [10 0];
— > bc= [3 0];
— > bd= [6 0];
— > ca= [5 0];
— > cb= [3 0];
— > cd= [7 0];
— > da= [4 0];
— > db= [6 0];
— > dc= [7 0];
— > U= [dc cb ba; dc ca ab; db bc ca; db ba ac; da ac cb; da ab
bc; cd db ba; cd da ab; cb bd da; cb ba ad;
ca ad db; ca ab bd; bd dc ca; bd da ac; bc ca ad; bc cd da; ba ad
dc; ba ac cd; ad dc cb; ad db bc; ac cd db;
ac cb bd; ab bd dc; ab bc cd];
Let’s sum up the rows of the obtained matrix and find the
smallest element:

12
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

— > Y=sum (U,2);


— > min (Y)
ans =
12.
The smallest distance is 12. Create matrix H and find the inter-
section of matrixes to find the string and define the path.
— > H= [12];
— > [c, iY, iH] =intersect (Y (:),H (:))
iH =
1.
iY =
5.
c=
12.
We see that the intersection of matrixes with the value of ele-
ment 12 points to row 5 in matrix Y. Row 5 in matrix T points
the way:
T (5,:)
ans =
4. 1. 1. 3. 3. 2.
The first answer is the shortest path 12 km path from city
4 to city 1, then from city 1 to city 3, from city 3 to city 2.
But, this answer may not be the only one, so let’s set the ele-
ment of the 5th row of the obtained matrix Y to a value greater
than the minimum distance of 12 km., for example 12+1=13 and
repeat the matrix crossing procedure
— > Y (5,1) =13;
— > [c, iY, iH] =intersect (Y (:),H (:));
Repeat this process and record the answers on the basis of the
row of the crossing until the crossing of matrices will not give the
empty set.

13
LUDMILA NAUMOVA

— PLACEMENTS

The number of places is limited, and only 3 (three) students


out of 5 will get a place in the hostel. Find all accommodation op-
tions.

To find solutions, remove the last columns in the matrix ob-


tained by permutations (5—3=2). Remove the two columns to leave
three columns, as only 3 people can get a place.
— > P (:, 5) = []
— > P (:, 4) = []
We exclude the same rows in the matrix P:
— > M=unique (P, 1)
Let’s sort the rows of the resulting matrix M in descending
order:
— > V=sort (M,‘c’)
Again, delete the same rows of the sorted matrix V:
— > Y=unique (V, 1)
Get the desired answer, each row of the matrix will be as
a placement option.
The number of such placements will be equal to the number
of lines:
— > size (Y)
And the number of columns is the number of places that stu-
dents had to be placed.

— FULFILLMENT OF ADDITIONAL CONDITIONS


IN THE TASK

But the Dean set a condition that the 3rd, 1st, and 5th stu-
dents do not settle together. Let’s set this condition as a one-di-
mensional matrix Z:
— > Z= [3 1 5]
Z=

14
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

3. 1. 5.
Let’s sort the matrix Z in descending order:
— > R=gsort (Z)
Find the intersection of rows of matrixes R and Y:
T=intersect (R,Y,1)
Finding the common row index for R and Y matrixes
— > [c, iR, iY] =intersect (R,Y,1)
iY =
6.
iR =

1.
c=
5. 3. 1.
Thus, it is necessary to delete the 6th row of the
matrix Y in order to fulfill the Dean’s condition
and get the final answers in the form of matrix
rows:

— > Y (6,:) = []
Let’s once again we find the intersection of the rows of matri-
ces R and Y, and so we repeat until the intersection of matrices is
empty set.
We get the final answers to the task — these are the rows
of the matrix Y as all possible answers.

— COMPLEX PLACEMENTS

Task-model №1—1
Another example of accommodation: 9 students can be accom-
modated only in 2 rooms in pairs, that is only 4 places. Find all
these pairs-solutions.
To save space, suppose that we have already found a solution
to place 9 students in 4 places in the form of rows of the matrix
(assume matrix E) similar to the Task-model №1 (get a matrix
of 4 columns-the number of seats, and rows — equal to the num-

15
LUDMILA NAUMOVA

ber of solutions). Now, of all the options presented in each


of therow of the resulting matrix E it is necessary to choose all
kinds of options pairs. To do this, each row of the resulting matrix
e is represented as an initial condition — a one-dimensional ma-
trix, of the four numbers of one-dimensional matrices it is neces-
sary to obtain all possible variants of pairs. Each option will be
presented in pairs that are received in rows of the final matrix.
The variant of obtaining all possible pairs from one one-di-
mensional p matrix is presented below, but the finding of all possi-
ble pairs from other one-dimensional matrices is similar.
Decision:
Program start:
loading the source environment
— > n= [5 3 1 4]
n=
5. 3. 1. 4.
Find all possible permutations of the matrix row P
— > P=perms (n)
Since there are 2 rooms under the conditions of the problem,
divide the matrix P into 2 matrices with an equal number
of columns: that is, one matrix with the first two columns, the
other with the 3rd and 4th columns, and sort the rows of the ob-
tained two matrices in descending order.
— > F=P

— > F (:,4) = []
— > F (:,3) = []
— > V=gsort (F,‘c’)
— > K=P

— > K (:,1) = []
— > K (:,1) = []
— > Q=gsort (K,‘c’)
After sorting the two matrices, combine them and delete the
same rows in the resulting matrix
— > W=cat (2,V,Q)

16
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

Exclude the same rows and find the answer you are looking for
— > U=unique (W,1)
Answer: variants of pairs in each row of the matrix, that is, the
first option-the first row — is the 1st room of two students in the
1st and 2nd column, ie, under the numbers 3,1; 2nd room of two
students in the 3rd and 4th column, ie, under the numbers 5,4. The
second option is the 2nd row — this is the 1st room of two stu-
dents in the 1st and 2nd column, i.e. under the numbers 4.1; 2nd
room of two students in the 3rd and 4th column, i.e. under the
numbers 5.3, etc. and so all the rows of the resulting matrix U. But
as we wrote at the beginning of solving the task — model №1—1,
this is only the answer obtained from one of the rows of the ma-
trix E. All the same should be done with all the rows of the ma-
trix E.

— SOLVING THE PROBLEMS OF COMBINATIONS


AND ARRANGEMENTS WITH THE HELP OF ZEROS
IN THE ROWS OF THE ORIGINAL MATRIX

Numbers 2, 9.6. Problem: is it possible to choose


among these numbers such that their sum will
give 17?
Since we need to pick up all sorts of combinations
and find their sum, we will set a one-dimensional
matrix with an equal number of zeros and how
many of the original numbers:
loading the source environment
загрузка исходного окружения
Solving the problems of combinations and
arrangements with the help of zeros in the rows
of the original matrix.
Numbers 2, 9.6. Problem: is it possible to choose
among these numbers such that their sum will
give 17?

17
LUDMILA NAUMOVA

Since we need to pick up all sorts of combinations


and find their sum, we will set a one-dimensional
matrix with an equal number of zeros and how
many of the original numbers:
loading the source environment
— > n= [0 0 0 2 9 6]
n=
0. 0. 0. 2. 9. 6.
Let’s sort the initial matrix for convenience
of calculations in descending order.
— > m=gsort (n)
m=
9. 6. 2. 0. 0. 0.
Find all variants of the permutations
— > v=perms (m)
Remove the last columns-3 columns, so the number
of additional zeros in the original matrix was 3.
— > v (:,6) = []
— > v (:,5) = []
— > v (:,4) = []
Sort the resulting matrix in descending order:
— > x=gsort (v)
Exclude the same lines:
— > M=unique (v,1)
Again, sort in descending order, but not the entire
matrix as a whole, and its rows
— > Z=gsort (M,‘c’)
Again, exclude the same rows:
— > H=unique (Z,1)
Get the matrix of size:
— > size (H)
Sum the elements row by row

18
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

sum (H,2)
We perform an action on each received sum line
by row:
— > D=sum (H,2) -17
Set the zero matrix:
— > S=0

Find the intersection of two matrices


— > [c, iD, iS] =intersect (D (:),S (:))
iS =
1.
iD =
8.
c=
0.
Find a string equal to iD=8
— > H (8,:)

The answer looking for is found, but make sure it’s the
only one.
Find again the intersection of two matrices
— > [c, iD, iS] =intersect (D (:),S (:))
Make sure that the intersection gives an empty set, if not, then
repeat the procedure of crossing two matrices, previously chang-
ing the value in the eighth row of the matrix D from zero to an-
other.

— COMBINATIONS

Example. The particle consists of 3 quarks, all combinations


are possible. Quarks of three types — green, blue, red. Find all pos-
sible combinations of quarks in one particle.

If we denote three quarks as numbers 1,2,3, respectively


(green, blue, red), then to find the combinations as the initial data,
we need to set a one-dimensional matrix of 9 numbers (the num-

19
LUDMILA NAUMOVA

ber of each quark is repeated three times, since only three quarks
can be a particle):
— > n= [1 1 1 2 2 2 3 3 3]
Let’s sort the initial matrix for convenience of calculations
in descending order.
— > m=gsort (n)
Now we find all possible permutations from 1 to 9.
— > P=perms (m)
Remove the last columns-6 columns, as the number of addi-
tional numbers in the original matrix was 6.
— > v (:,9) = []
— > v (:,8) = []
— > v (:,7) = []
— > v (:,6) = []
— > v (:,5) = []
— > v (:,4) = []
Sort the resulting matrix in descending order:
— > x=gsort (v)
Exclude the same rows
— > M=unique (v,1)
Again, let’s sort in descending order, but not the whole matrix,
but the rows
— > Z=gsort (M,‘c’)
Again, exclude the same rows:
— > H=unique (Z,1)
Get the matrix of size:
— > size (H)
The resulting matrix will be the answer, each row of the ma-
trix is a variant of the answer, and the number of rows of the ma-
trix is the number of variants, the number of columns of the matrix
is the number of quarks of which the particle consists — 3.

20
CHAPTER 2. DETAILED SOLUTION
OF PROBLEMS IN THE PROGRAM
SCILAB 6.0.1

2.1. MODEL-PROBLEM №1

Let’s say you’re hosting a group of 5 University


students. The number of places is limited, and
only 3 (three) students will get a place in the
hostel. The situation is complicated by the fact
that the Dean has provided you with three
students who can not live together, and asked
that this three did not get into the final version.
Here is an algorithm for solving this problem in the
program Scilab 6.0.1:
1. Let’s give each student a number in order: 1 — first
student;
2 — 2nd student....etc to 5. As a one-dimensional
matrix n
Program start:
loading the source environment
— > n= [1 2 3 4 5]
n=
1. 2. 3. 4. 5.
Now we find all possible permutations from 1 to 5,
there will be 120.
— > P=perms (n)
P=

21
LUDMILA NAUMOVA

5. 4. 3. 2. 1.
5. 4. 3. 1. 2.
5. 4. 2. 3. 1.
5. 4. 2. 1. 3.
5. 4. 1. 3. 2.
5. 4. 1. 2. 3.
5. 3. 4. 2. 1.
5. 3. 4. 1. 2.
5. 3. 2. 4. 1.
5. 3. 2. 1. 4.
5. 3. 1. 4. 2.
5. 3. 1. 2. 4.
5. 2. 4. 3. 1.
5. 2. 4. 1. 3.
5. 2. 3. 4. 1.
5. 2. 3. 1. 4.
5. 2. 1. 4. 3.
5. 2. 1. 3. 4.
5. 1. 4. 3. 2.
5. 1. 4. 2. 3.
5. 1. 3. 4. 2.
5. 1. 3. 2. 4.
5. 1. 2. 4. 3.
5. 1. 2. 3. 4.
4. 5. 3. 2. 1.
4. 5. 3. 1. 2.
4. 5. 2. 3. 1.
4.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5. 4. 3.
2. 1. 5. 3. 4.
2. 1. 4. 5. 3.
2. 1. 4. 3. 5.
2. 1. 3. 5. 4.
2. 1. 3. 4. 5.
1. 5. 4. 3. 2.
1. 5. 4. 2. 3.
1. 5. 3. 4. 2.

1. 5. 3. 2. 4.
1. 5. 2. 4. 3.
1. 5. 2. 3. 4.
1. 4. 5. 3. 2.
1. 4. 5. 2. 3.
1. 4. 3. 5. 2.
1. 4. 3. 2. 5.
1. 4. 2. 5. 3.

24
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

1. 4. 2. 3. 5.
1. 3. 5. 4. 2.
1. 3. 5. 2. 4.
1. 3. 4. 5. 2.
1. 3. 4. 2. 5.
1. 3. 2. 5. 4.
1. 3. 2. 4. 5.
1. 2. 5. 4. 3.
1. 2. 5. 3. 4.
1. 2. 4. 5. 3.
1. 2. 4. 3. 5.
1. 2. 3. 5. 4.
1. 2. 3. 4. 5.
Since there are only three places, remove the last
columns of the matrix P to three. That is, first
remove the fifth column:
— > P (:,5) = []
P=

5. 4. 3. 2.
5. 4. 3. 1.
5. 4. 2. 3.
5. 4. 2. 1.
5. 4. 1. 3.
5. 4. 1. 2.
5. 3. 4. 2.
5. 3. 4. 1.
5. 3. 2. 4.
5. 3. 2. 1.
5. 3. 1. 4.
5. 3. 1. 2.
5. 2. 4. 3.
5. 2. 4. 1.
5. 2. 3. 4.
5. 2. 3. 1.
5. 2. 1. 4.
5. 2. 1. 3.

25
LUDMILA NAUMOVA

5. 1. 4. 3.
5. 1. 4. 2.
5. 1. 3. 4.
5. 1. 3. 2.
5. 1. 2. 4.
5. 1. 2. 3.
4. 5. 3. 2.
4. 5. 3. 1.
4. 5. 2. 3.
4. 5. 2. 1.
4. 5. 1. 3.
4. 5. 1. 2.
4. 3. 5. 2.
4. 3. 5. 1.
4. 3. 2. 5.
4. 3. 2. 1.
4. 3. 1. 5.
4. 3. 1. 2.
4. 2. 5. 3.
4. 2. 5. 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
2. 1. 4.
2. 1. 4.
2. 1. 3.
2. 1. 3.
1. 5. 4.
1. 5. 4.
1. 5. 3.

1. 5. 3.
1. 5. 2.
1. 5. 2.
1. 4. 5.
1. 4. 5.
1. 4. 3.
1. 4. 3.
1. 4. 2.

31
LUDMILA NAUMOVA

1. 4. 2.
1. 3. 5.
1. 3. 5.
1. 3. 4.
1. 3. 4.
1. 3. 2.
1. 3. 2.
1. 2. 5.
1. 2. 5.
1. 2. 4.
1. 2. 4.
1. 2. 3.
1. 2. 3.
We exclude the same rows in the matrix P:
— > M=unique (P,1)
M=

1. 2. 3.
1. 2. 4.
1. 2. 5.
1. 3. 2.
1. 3. 4.
1. 3. 5.
1. 4. 2.
1. 4. 3.
1. 4. 5.
1. 5. 2.
1. 5. 3.
1. 5. 4.
2. 1. 3.
2. 1. 4.
2. 1. 5.
2. 3. 1.
2. 3. 4.
2. 3. 5.
2. 4. 1.
2. 4. 3.

32
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

2. 4. 5.
2. 5. 1.
2. 5. 3.
2. 5. 4.
3. 1. 2.
3. 1. 4.
3. 1. 5.
3. 2. 1.
3. 2. 4.
3. 2. 5.
3. 4. 1.
3. 4. 2.
3. 4. 5.
3. 5. 1.
3. 5. 2.
3. 5. 4.
4. 1. 2.
4. 1. 3.
4. 1. 5.
4. 2. 1.
4. 2. 3.
4. 2. 5.
4. 3. 1.
4. 3. 2.
4. 3. 5.
4. 5. 1.
4. 5. 2.
4. 5. 3.
5. 1. 2.
5. 1. 3.
5. 1. 4.
5. 2. 1.
5. 2. 3.
5. 2. 4.
5. 3. 1.
5. 3. 2.

33
LUDMILA NAUMOVA

5. 3. 4.
5. 4. 1.
5. 4. 2.
5. 4. 3.
Let’s sort the rows of the resulting matrix M
in descending order
— > V=gsort (M,‘c’)
V=

3. 2. 1.
4. 2. 1.
5. 2. 1.
3. 2. 1.
4. 3. 1.
5. 3. 1.
4. 2. 1.
4. 3. 1.
5. 4. 1.
5. 2. 1.
5. 3. 1.
5. 4. 1.
3. 2. 1.
4. 2. 1.
5. 2. 1.
3. 2. 1.
4. 3. 2.
5. 3. 2.
4. 2. 1.
4. 3. 2.
5. 4. 2.
5. 2. 1.
5. 3. 2.
5. 4. 2.
3. 2. 1.
4. 3. 1.
5. 3. 1.
3. 2. 1.

34
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

4. 3. 2.
5. 3. 2.
4. 3. 1.
4. 3. 2.
5. 4. 3.
5. 3. 1.
5. 3. 2.
5. 4. 3.
4. 2. 1.
4. 3. 1.
5. 4. 1.
4. 2. 1.
4. 3. 2.
5. 4. 2.
4. 3. 1.
4. 3. 2.
5. 4. 3.
5. 4. 1.
5. 4. 2.
5. 4. 3.
5. 2. 1.
5. 3. 1.
5. 4. 1.
5. 2. 1.
5. 3. 2.
5. 4. 2.
5. 3. 1.
5. 3. 2.
5. 4. 3.
5. 4. 1.
5. 4. 2.
5. 4. 3.
Again, delete the same rows of the sorted matrix V:
— > Y=unique (V,1)
Y=

35
LUDMILA NAUMOVA

3. 2. 1.
4. 2. 1.
4. 3. 1.
4. 3. 2.
5. 2. 1.
5. 3. 1.
5. 3. 2.
5. 4. 1.
5. 4. 2.
5. 4. 3.
— > size (Y)
ans =
10. 3.
It turned out 10 accommodation options for
5 students in three places. But the Dean set
a condition that the 3rd, 1st, and 5th students do
not settle together. Let’s set this condition as
a one-dimensional matrix Z:
— > Z= [3 1 5]
Z=

3. 1. 5.
Let’s sort the matrix Z in descending order:
— > R=gsort (Z)
R=

5. 3. 1.
Find the intersection of rows of matrices R and Y:
T=intersect (R, Y,1)
T=

5. 3. 1.
Finding the common row index for R and Y matrices:
— > [c, iR, iY] =intersect (R,Y,1)
iY =
6.
iR =

36
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

1.
c=
5. 3. 1.
Thus, it is necessary to delete the 6th row of the
matrix Y in order to fulfill the Dean’s condition
and get the final answers in the form of matrix
rows:
Y (6,:) = []
Y=

3. 2. 1.
4. 2. 1.
4. 3. 1.
4. 3. 2.
5. 2. 1.
5. 3. 2.
5. 4. 1.
5. 4. 2.
5. 4. 3.
Let’s once again we find the intersection of the rows
of matrices R and Y, and so we repeat until the
intersection of matrices is empty set.

37
LUDMILA NAUMOVA

We get the final answers to the task — these are the


rows of the matrix Y as all possible answers.
The answer of the problem is 9 variants (each answer
is a row of matrix Y).
Similarly, problems are solved with a large number
of students and places, and with a large number
of conditions of the Dean. The algorithm is the
same, only the matrix and the number
of solutions will be huge, it all depends on the
resolution of the computer, but the General
algorithm exists. But in the end, the solution
exists in the form of an algorithm.
The whole essence of the solution is reduced to the
operations of intersection of sets, sorting,
elimination of identical sets, permutation —
in a word, operating with a natural series (its
elements) in the form of rows and columns
of matrices. If in Scilab of the combinatorics
implemented a function of a permutation as
a function of perms, combinations of no, but
in this task you learn how to solve this problem
of combinatorics in the form of an algorithm.

2.2. TASK-MODEL №1—1

Another example of accommodation: 9 students can be accom-


modated only in 2 rooms in pairs, that is only 4 places. Find all
these pairs-solutions.
To save space, suppose that we have already found a solution
to place 9 students in 4 places in the form of rows of the matrix
(assume matrix E) similar to the problem number 1 (get a matrix
of 4 columns-the number of seats, and rows — equal to the num-
ber of solutions). Now, of all the options presented in each of the
row of the resulting matrix E it is necessary to choose all kinds
of pairs variants. To do this, each row of the resulting matrix e is
represented as an initial condition — a one-dimensional matrix,

38
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

of the four numbers of one-dimensional matrices it is necessary


to obtain all possible variants of pairs. Each option will be pre-
sented in pairs that are received in rows of the final matrix.
The variant of obtaining all possible pairs from one one-di-
mensional p matrix is presented below, but the finding of all possi-
ble pairs from other one-dimensional matrices is similar.

Decision:
Program start:
loading the source environment
— > n= [5 3 1 4]
n=
5. 3. 1. 4.
We find all possible permutations of the row of the
matrix E
— > P=perms (n)
P=

4. 1. 3. 5.
4. 1. 5. 3.
4. 3. 1. 5.
4. 3. 5. 1.
4. 5. 1. 3.
4. 5. 3. 1.
1. 4. 3. 5.
1. 4. 5. 3.
1. 3. 4. 5.
1. 3. 5. 4.
1. 5. 4. 3.
1. 5. 3. 4.
3. 4. 1. 5.
3. 4. 5. 1.
3. 1. 4. 5.
3. 1. 5. 4.
3. 5. 4. 1.
3. 5. 1. 4.
5. 4. 1. 3.

39
LUDMILA NAUMOVA

5. 4. 3. 1.
5. 1. 4. 3.
5. 1. 3. 4.
5. 3. 4. 1.
5. 3. 1. 4.
Since rooms 2 under the conditions of the problem,
divide the matrix P into 2 matrices with an equal
number of columns: that is, one matrix with the
first two columns, the other with the 3rd and 4th
columns.

— > F=P
F=

4. 1. 3. 5.
4. 1. 5. 3.
4. 3. 1. 5.
4. 3. 5. 1.
4. 5. 1. 3.
4. 5. 3. 1.
1. 4. 3. 5.
1. 4. 5. 3.
1. 3. 4. 5.
1. 3. 5. 4.
1. 5. 4. 3.
1. 5. 3. 4.
3. 4. 1. 5.
3. 4. 5. 1.
3. 1. 4. 5.
3. 1. 5. 4.
3. 5. 4. 1.
3. 5. 1. 4.
5. 4. 1. 3.
5. 4. 3. 1.
5. 1. 4. 3.

40
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

5. 1. 3. 4.
5. 3. 4. 1.
5. 3. 1. 4.

— > F (:,4) = []
F=

4. 1. 3.
4. 1. 5.
4. 3. 1.
4. 3. 5.
4. 5. 1.
4. 5. 3.
1. 4. 3.
1. 4. 5.
1. 3. 4.
1. 3. 5.
1. 5. 4.
1. 5. 3.
3. 4. 1.
3. 4. 5.
3. 1. 4.
3. 1. 5.
3. 5. 4.
3. 5. 1.
5. 4. 1.
5. 4. 3.
5. 1. 4.
5. 1. 3.
5. 3. 4.
5. 3. 1.

— > F (:,3) = []
F=

41
LUDMILA NAUMOVA

4. 1.
4. 1.
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5. 4.
4. 3.
3. 4.
1. 5.
5. 1.
4. 5.
5. 4.
4. 1.
1. 4.
1. 3.
3. 1.
4. 3.
3. 4.
4. 1.
1. 4.

— > Q=gsort (K,‘c’)


Q=

5. 3.
5. 3.
5. 1.
5. 1.
3. 1.
3. 1.
5. 3.
5. 3.
5. 4.

45
LUDMILA NAUMOVA

5. 4.
4. 3.
4. 3.
5. 1.
5. 1.
5. 4.
5. 4.
4. 1.
4. 1.
3. 1.
3. 1.
4. 3.
4. 3.
4. 1.
4. 1.
After sorting the two matrices, combine them and
delete the same rows in the resulting matrix
— > W=cat (2,V,Q)
W=

4. 1. 5. 3.
4. 1. 5. 3.
4. 3. 5. 1.
4. 3. 5. 1.
5. 4. 3. 1.
5. 4. 3. 1.
4. 1. 5. 3.
4. 1. 5. 3.
3. 1. 5. 4.
3. 1. 5. 4.
5. 1. 4. 3.
5. 1. 4. 3.
4. 3. 5. 1.
4. 3. 5. 1.
3. 1. 5. 4.
3. 1. 5. 4.
5. 3. 4. 1.

46
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

5. 3. 4. 1.
5. 4. 3. 1.
5. 4. 3. 1.
5. 1. 4. 3.
5. 1. 4. 3.
5. 3. 4. 1.
5. 3. 4. 1.
— > U=unique (W,1)
U=

3. 1. 5. 4.
4. 1. 5. 3.
4. 3. 5. 1.
5. 1. 4. 3.
5. 3. 4. 1.
5. 4. 3. 1.
Answer: variants of pairs in each row of the matrix,
that is, the first option-the first row — is the 1st
room of two students in the 1st and 2nd column,
ie, under the numbers 3,1; 2nd room of two
students in the 3rd and 4th column, ie, under the
numbers 5,4. The second option is the 2nd row —
this is the 1st room of two students in the 1st and
2nd column, i.e. under the numbers 4.1; 2nd room
of two students in the 3rd and 4th column, i.e.
under the numbers 5.3, etc. and so all the rows
of the resulting matrix U. But as we wrote at the
beginning of the solution of the task-model №1—
1, this is only the answer obtained from one
of the rows of the matrix E. All the same should
be done with all the rows of the matrix E.

47
LUDMILA NAUMOVA

2.3. TASK-MODEL №2

Numbers 2, 9, 6. Problem: is it possible to choose


among these numbers such that their sum will
give 17?
Decision:
program start:
loading the source environment
— > n= [0 0 0 2 9 6]
n=
0. 0. 0. 2. 9. 6.
— > m=gsort (n)
m=
9. 6. 2. 0. 0. 0.
— > v=perms (m)
— > v (:,6) = []
— > v (:,5) = []
— > v (:,4) = []

— > x=gsort (v)


x=
— > size (v)
ans =
720. 3.
— > M=unique (v,1)
— > Z=gsort (M,‘c’)
— > H=unique (Z,1)
H=

0. 0. 0.
2. 0. 0.
6. 0. 0.
6. 2. 0.
9. 0. 0.
9. 2. 0.
9. 6. 0.
9. 6. 2.

48
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

— > size (H)


ans =
8. 3.
Find the sum of the numbers in the rows line
by rows:
sum (H,2)
ans =
0.
2.
6.
8.
9.
11.
15.
17.
Find the difference from the obtained amounts
— > D=sum (H,2) -17
D=

— 17.
— 15.
— 11.
— 9.
— 8.
— 6.
— 2.
0.
Set the zero matrix
— > S=0
S=

0.
Find the intersection with the zero matrix:
— > [c, iD, iS] =intersect (D (:),S (:))
iS =
1.
iD =

49
LUDMILA NAUMOVA

8.
c=
0.
The eighth line intersects with the zero matrix:
— > H (8,:)

ans =
9. 6. 2.
The answer is: 9,6,2.
To exclude another answer, change the value in the
eighth row of the matrix D to another number, for
example, 1 and again find the intersection of the
zero matrix with the matrix D and so on until the
intersection gives an empty set.

50
CONCLUSION
The main advantage of the program Scilab in solving NP-prob-
lems — is the presence of commands sort, permutation, intersec-
tion of sets, removing the same rows or columns from which you
can find the placement and combinations. However, these com-
mands are not yet available for individual parts of rows and parts
of columns, which complicates the task (or vice versa for entire
blocks of rows and columns). Unfortunately, the program Scilab is
not yet perfect for solving NP-problems, there are still many oper-
ations that would be useful in solving NP-problems and have to go
around. If the commands used in Excel tables were inserted into
the Scilab program for the matrices, this would make the matter
much easier. A table in Excel plays the role of a matrix in Scilab.
For example, in Excel — there is a copy of any part of the table
and create new tables from it, insert and delete both columns and
rows of the table, and entire blocks of columns or rows from an-
other table in any interval between columns or rows, for each ele-
ment of the table, you can divide a large table into tables by the
specified columns or rows, you can set the table elements., which
can be not numbers, and alphabetic characters and set the formula
in the index for them (meaning that the table in Excel simulates
the matrix in the program Scilab). The synthesis of the two pro-
grammes would yield tangible results.
But, despite all the shortcomings, we can see how to build al-
gorithms and in what direction you can go in solving NP-problems.
The solution of problems can lie on the surface, but we can
not always see at the right angle. Example: Fermat’s famous last
theorem. The farm found a short elegant solution, only the fields
on the page were not enough. The solution was found in our time,
but it took many pages. Let us presume that most likely a short
proof would look like this: Fermat’s Theorem

51
LUDMILA NAUMOVA

x, y, z, n are natural numbers, n is greater than 2


Evidence from the opposite:
Imagine that

(1)
Then, equation (1) can be represented as (2) :

(2)
Equation (2) of the second degree is obtained. This equation is
Diophantine, since the roots of the equation must be natural num-
bers. This equation is Diophantine, since the roots of the equation
must be natural numbers. But Diophantine equation of the form (2)
has the solution to Pythagorean triples. The General form of the

52
NP=P? ALGORITHMS FOR SOLVING NP-PROBLEMS BY MATRIX METHOD
IN SCILAB PROGRAM

equation for Pythagorean triples is:

(3)
k, a, b, c — natural number.
a, b, c — Pythagorean triplets.
Compare equations (2) and (3). There are no solutions to the
equation (2), since the form of equation (2) cannot be reduced
to the form (3), it is impossible to find such a natural number k,
which would lead equation (2) to the form of equation (3). It fol-
lows that equation (1) has no solutions. The reader can check the
arguments and write to e — mail: mathmillena@mail.ru. But it evi-
dence was a retreat to say that the solution might be on the sur-
face.

53
LUDMILA NAUMOVA

The author is confident that more and more NP-problems will


move into the category of P — problems. This process is inevitable
with the development of programs and the growth of computer
power.

54

Вам также может понравиться