Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Binary paint shop problem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
Binary paint shop problem
Commits
6a159c17
Commit
6a159c17
authored
1 year ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Další algoritmy: rg, rsg, local_improving
parent
ea4d7458
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
algo/local_improving.cpp
+64
-0
64 additions, 0 deletions
algo/local_improving.cpp
algo/rg.cpp
+42
-0
42 additions, 0 deletions
algo/rg.cpp
algo/rsg.cpp
+96
-0
96 additions, 0 deletions
algo/rsg.cpp
build.mk
+3
-0
3 additions, 0 deletions
build.mk
config.mk
+1
-1
1 addition, 1 deletion
config.mk
with
206 additions
and
1 deletion
algo/local_improving.cpp
0 → 100644
+
64
−
0
View file @
6a159c17
#include
"../pipe.h"
#include
<functional>
#include
<cassert>
// ****** ARGS ********
// <int> max number of changes
using
std
::
pair
;
const
int
VERSION
=
2
;
const
bool
ALLOW_INPUT_MISTAKES
=
0
;
const
bool
ALLOW_MISTAKES
=
0
;
vector
<
bool
>
solve
(
int
n
,
vector
<
int
>
input
,
vector
<
bool
>
out
,
int
argc
,
char
const
*
const
*
argv
)
{
assert
(
argc
==
1
);
int
max_changes
=
atoi
(
argv
[
0
]);
assert
(
max_changes
>
0
);
vector
<
int
>
other
=
lib
::
gen_arr_other_car_of_type
(
n
,
input
);
std
::
function
<
bool
(
int
,
int
,
int
)
>
f
=
[
&
](
int
changes
,
int
score_diff
,
int
begin_index
)
{
for
(
int
i
=
begin_index
;
i
<
2
*
n
;
i
++
)
if
(
i
<
other
[
i
])
{
out
[
i
]
=
!
out
[
i
];
out
[
other
[
i
]]
=
!
out
[
other
[
i
]];
int
new_score_diff
=
score_diff
;
if
(
i
)
new_score_diff
+=
out
[
i
]
==
out
[
i
-
1
]
?
-
1
:
1
;
if
(
i
+
1
!=
other
[
i
])
{
new_score_diff
+=
out
[
i
]
==
out
[
i
+
1
]
?
-
1
:
1
;
new_score_diff
+=
out
[
other
[
i
]]
==
out
[
other
[
i
]
-
1
]
?
-
1
:
1
;
}
if
(
other
[
i
]
!=
2
*
n
-
1
)
new_score_diff
+=
out
[
other
[
i
]]
==
out
[
other
[
i
]
+
1
]
?
-
1
:
1
;
if
(
new_score_diff
<
0
)
{
fprintf
(
stderr
,
"%d %d %d
\n
"
,
changes
,
i
,
new_score_diff
);
return
true
;
}
if
(
changes
+
1
<
max_changes
)
if
(
f
(
changes
+
1
,
new_score_diff
,
i
+
1
))
return
true
;
out
[
i
]
=
!
out
[
i
];
out
[
other
[
i
]]
=
!
out
[
other
[
i
]];
}
return
false
;
};
while
(
f
(
0
,
0
,
0
))
{
fo
(
i
,
2
*
n
)
fprintf
(
stderr
,
"%c"
,
out
[
i
]
?
'1'
:
'0'
);
fprintf
(
stderr
,
"
\n
"
,
n
);
}
return
out
;
}
This diff is collapsed.
Click to expand it.
algo/rg.cpp
0 → 100644
+
42
−
0
View file @
6a159c17
#include
"../main.h"
const
int
VERSION
=
1
;
const
bool
ALLOW_MISTAKES
=
0
;
vector
<
bool
>
solve
(
int
n
,
vector
<
int
>
input
,
int
argc
,
char
const
*
const
*
argv
)
{
if
(
n
==
0
)
return
vector
<
bool
>
();
vector
<
int
>
other
=
lib
::
gen_arr_other_car_of_type
(
n
,
input
);
vector
<
bool
>
out
(
2
*
n
);
vector
<
int
>
r_input
(
2
*
n
-
2
);
for
(
int
i
=
1
;
i
<
2
*
n
;
i
++
)
if
(
i
!=
other
[
0
])
r_input
[
i
-
1
-
(
i
>
other
[
0
])]
=
input
[
i
]
-
(
input
[
i
]
>
input
[
0
]);
auto
r_out
=
solve
(
n
-
1
,
r_input
,
argc
,
argv
);
for
(
int
i
=
1
;
i
<
2
*
n
;
i
++
)
if
(
i
!=
other
[
0
])
out
[
i
]
=
r_out
[
i
-
1
-
(
i
>
other
[
0
])];
if
(
other
[
0
]
==
2
*
n
-
1
)
{
out
[
0
]
=
1
;
out
[
other
[
0
]]
=
0
;
}
else
if
(
other
[
0
]
==
1
)
{
out
[
0
]
=
!
out
[
2
];
out
[
1
]
=
out
[
2
];
}
else
{
if
(
out
[
other
[
0
]
-
1
]
==
out
[
1
]
&&
out
[
other
[
0
]
+
1
]
==
out
[
1
])
out
[
0
]
=
!
out
[
1
];
else
out
[
0
]
=
out
[
1
];
out
[
other
[
0
]]
=
!
out
[
0
];
}
return
out
;
}
This diff is collapsed.
Click to expand it.
algo/rsg.cpp
0 → 100644
+
96
−
0
View file @
6a159c17
#include
"../main.h"
const
int
VERSION
=
1
;
const
bool
ALLOW_MISTAKES
=
0
;
vector
<
int
>
solve_star
(
int
n
,
vector
<
int
>
input
)
{
if
(
n
==
0
)
return
vector
<
int
>
();
vector
<
int
>
other
=
lib
::
gen_arr_other_car_of_type
(
n
,
input
);
vector
<
int
>
out
(
2
*
n
);
// 0: * -1, 1: colors
vector
<
int
>
r_input
(
2
*
n
-
2
);
for
(
int
i
=
1
;
i
<
2
*
n
;
i
++
)
if
(
i
!=
other
[
0
])
r_input
[
i
-
1
-
(
i
>
other
[
0
])]
=
input
[
i
]
-
(
input
[
i
]
>
input
[
0
]);
auto
r_out
=
solve_star
(
n
-
1
,
r_input
);
for
(
int
i
=
1
;
i
<
2
*
n
;
i
++
)
if
(
i
!=
other
[
0
])
out
[
i
]
=
r_out
[
i
-
1
-
(
i
>
other
[
0
])];
if
(
other
[
0
]
==
2
*
n
-
1
)
// B
{
out
[
0
]
=
1
;
out
[
other
[
0
]]
=
-
1
;
}
else
if
(
other
[
0
]
==
1
)
// A
{
out
[
0
]
=
-
out
[
2
];
out
[
1
]
=
out
[
2
];
}
else
if
(
out
[
other
[
0
]
-
1
]
==
out
[
other
[
0
]
+
1
]
&&
out
[
other
[
0
]
-
1
])
// C
{
out
[
0
]
=
-
out
[
other
[
0
]
-
1
];
out
[
other
[
0
]]
=
out
[
other
[
0
]
-
1
];
}
else
if
(
out
[
other
[
0
]
+
1
]
&&
out
[
other
[
0
]
-
1
])
// D
{
out
[
0
]
=
out
[
1
];
out
[
other
[
0
]]
=
-
out
[
1
];
}
else
if
(
out
[
1
]
==
-
out
[
other
[
0
]
-
1
]
||
out
[
1
]
==
-
out
[
other
[
0
]
+
1
])
// E
{
out
[
0
]
=
out
[
1
];
out
[
other
[
0
]]
=
-
out
[
1
];
}
else
// F
{
out
[
0
]
=
out
[
1
];
out
[
other
[
0
]]
=
-
out
[
1
];
if
(
!
out
[
other
[
0
]
-
1
])
{
out
[
other
[
0
]
-
1
]
=
-
out
[
1
];
out
[
other
[
other
[
0
]
-
1
]]
=
out
[
1
];
}
else
{
out
[
other
[
0
]
+
1
]
=
-
out
[
1
];
out
[
other
[
other
[
0
]
+
1
]]
=
out
[
1
];
}
}
if
(
other
[
1
]
!=
2
&&
other
[
1
]
!=
2
*
n
-
1
&&
out
[
1
-
1
]
&&
out
[
1
+
1
]
&&
out
[
other
[
1
]
-
1
]
&&
out
[
other
[
1
]
+
1
])
// G
{
int
diffs
=
0
;
diffs
+=
out
[
1
]
!=
out
[
1
-
1
];
diffs
+=
out
[
1
]
!=
out
[
1
+
1
];
diffs
+=
out
[
other
[
1
]]
!=
out
[
other
[
1
]
-
1
];
diffs
+=
out
[
other
[
1
]]
!=
out
[
other
[
1
]
+
1
];
if
(
diffs
==
2
)
{
out
[
1
]
=
out
[
other
[
1
]]
=
0
;
}
}
//fo(i, 2*n) fprintf(stderr, "%c", out[i]?out[i]==1?'1':'0':'*');
//fprintf(stderr, "\n", n);
return
out
;
}
vector
<
bool
>
solve
(
int
n
,
vector
<
int
>
input
,
int
argc
,
char
const
*
const
*
argv
)
{
vector
<
int
>
other
=
lib
::
gen_arr_other_car_of_type
(
n
,
input
);
auto
out_star
=
solve_star
(
n
,
input
);
vector
<
bool
>
out
(
2
*
n
);
fo
(
i
,
2
*
n
)
{
if
(
out_star
[
i
])
out
[
i
]
=
out_star
[
i
]
>
0
;
else
out
[
i
]
=
i
>
other
[
i
];
}
return
out
;
}
This diff is collapsed.
Click to expand it.
build.mk
+
3
−
0
View file @
6a159c17
...
@@ -58,7 +58,10 @@ endef
...
@@ -58,7 +58,10 @@ endef
$(
eval
$(
call standard_algo,greedy
))
$(
eval
$(
call standard_algo,greedy
))
$(
eval
$(
call standard_algo,maxcut
))
$(
eval
$(
call standard_algo,maxcut
))
$(
eval
$(
call standard_algo,semidef_prog
))
$(
eval
$(
call standard_algo,semidef_prog
))
$(
eval
$(
call standard_algo,rg
))
$(
eval
$(
call standard_algo,rsg
))
$(
eval
$(
call standard_pipe,fix_naive
))
$(
eval
$(
call standard_pipe,fix_naive
))
$(
eval
$(
call standard_pipe,fix_better
))
$(
eval
$(
call standard_pipe,fix_better
))
$(
eval
$(
call standard_pipe,local_improving
))
This diff is collapsed.
Click to expand it.
config.mk
+
1
−
1
View file @
6a159c17
algorithms
=
greedy maxcut fix_naive fix_better semidef_prog
algorithms
=
greedy maxcut fix_naive fix_better semidef_prog
local_improving rg rsg
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment