Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Makefile for program "cover" by Kari J. Nurmela.
#

CC = gcc
CXX = g++
LIBS= -lm

FLAGS= -ggdb -W # unoptimized, debuggable
#FLAGS= -W -O2 # optimized, not debuggable
#FLAGS= -ggdb -W # unoptimized, debuggable
FLAGS= -ffast-math -W -Ofast -D_GLIBCXX_PARALLEL# optimized, not debuggable

#if windows
#REMOVE= del cover.exe
Expand All @@ -20,12 +20,12 @@ OBJECTS= cover.o bincoef.o tables.o setoper.o solcheck.o exp.o arg.o pdo.o
CS= cover.c bincoef.c tables.c setoper.c solcheck.c exp.c arg.c pdo.c
AUTOBACKUPS= *~

.cc.o :
$(CC) $(FLAGS) -c $<
.c.o : $(CS)
$(CXX) $(FLAGS) -c $<

cover: $(OBJECTS)
$(REMOVE)
$(CC) -o cover $(OBJECTS) \
$(CXX) $(FLAGS) -lgomp -o cover $(OBJECTS) \
$(LIBS)

distrib:
Expand All @@ -35,7 +35,7 @@ distrib:
echo "NOTE: distribution contains files cover.tar.Z, cover.zip, and README."

clean:
$(DELETE) $(OBJECTS)
$(DELETE) $(OBJECTS) $(BCS) cover
$(DELETE) $(AUTOBACKUPS)
$(DELETE) core
$(DELETE) cover.tar
Expand Down
13 changes: 7 additions & 6 deletions arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/


#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include "cover.h"
#include "arg.h"
#include "tables.h"
Expand Down Expand Up @@ -103,10 +104,10 @@ void parseArguments(int argc, char **argv)
if((tmp = strchr(argv[i], '=')) == NULL)
errmsg(argv[i]);
eq = tmp - argv[i] + 1;
strncpy(name, argv[i], min(eq - 1, TMP_BUF_SIZE - 1));
name[min(eq - 1, TMP_BUF_SIZE - 1)] = '\0';
strncpy(value, argv[i] + eq, min(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1));
value[min(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1)] = '\0';
strncpy(name, argv[i], fmin(eq - 1, TMP_BUF_SIZE - 1));
name[(int)fmin(eq - 1, TMP_BUF_SIZE - 1)] = '\0';
strncpy(value, argv[i] + eq, (int)fmin(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1));
value[(int)fmin(strlen(argv[i]) - eq, TMP_BUF_SIZE - 1)] = '\0';
found = 0;
for(j = 0; j < OPT_COUNT; j++)
if(!strcmp(vars[j].varname, name)) {
Expand Down
126 changes: 65 additions & 61 deletions cover.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
#include <time.h>
#include "cover.h"
#include "bincoef.h"
#include "tables.h"
#include "tables.h"
#include "setoper.h"
#include "solcheck.h"
#include "arg.h"
#include "exp.h"
#include "pdo.h"

Expand Down Expand Up @@ -149,9 +152,68 @@ int compareVarieties(varietyType *a, varietyType *b) {
return 0;
}
}

char *logName, *resultName;
FILE *logFp, *resFp;
FILE *logFp, *resFp;

void printProblemParams(){
if(pack){
printf("Searching for a (%d,%d,%d,%d,%d) packing in %d blocks. (v,k,m,t,lambda)\n\n",
v,k,m,t,coverNumber,b);
}else{
printf("Searching for a (%d,%d,%d,%d,%d) covering in %d blocks. (v,k,m,t,lambda)\n\n",
v,k,m,t,coverNumber,b);
}
if(pack){
asprintf(&logName, "./solutions/P(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b);
}else{
asprintf(&logName, "./solutions/C(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b);
}
logFp = fopen(logName, "w");
if(!logFp) {
fprintf(stderr, "Can't open log file %s.\n", logName);
coverError(SEE_ABOVE_ERROR);
}
if(verbose && !pdoFlag){
printParams(stdout);
}
printParams(logFp);
}

void printProblemOutput(){
if(verbose){
printf("Result:\n" "-------\n"
"EndLimit = %d\n\n", endLimit);
}
if(verbose){
if(finalCost <= endLimit) {
printf("Solution:\n" "---------\n");
} else {
printf("EndLimit was not reached.\n\n");
if(verbose >= 2) {
printf("Inadequate solution:\n" "--------------------\n");
printSolution(stdout);
}
}
}
if(finalCost <= endLimit) {
if(verbose) {
printSolution(stdout);
}
if(pack){
asprintf(&resultName, "./solutions/P(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b);
}else{
asprintf(&resultName, "./solutions/C(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b);
}
resFp = fopen(resultName, "w");
if(!resFp) {
fprintf(stderr, "Can't open file %s.\n", resultName);
coverError(SEE_ABOVE_ERROR);
}
printSolution(resFp);
fclose(resFp);
}
}

int main(int argc, char **argv) {
costType retVal;
Expand Down Expand Up @@ -227,61 +289,3 @@ int main(int argc, char **argv) {
return !solFound; /* returns 0 if a solution was found */
}

void printProblemParams(){
if(pack){
printf("Searching for a (%d,%d,%d,%d,%d) packing in %d blocks. (v,k,m,t,lambda)\n\n",
v,k,m,t,coverNumber,b);
}else{
printf("Searching for a (%d,%d,%d,%d,%d) covering in %d blocks. (v,k,m,t,lambda)\n\n",
v,k,m,t,coverNumber,b);
}
if(pack){
asprintf(&logName, "./solutions/P(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b);
}else{
asprintf(&logName, "./solutions/C(%d,%d,%d,%d,%d) - %d.log", v,k,m,t,coverNumber,b);
}
logFp = fopen(logName, "w");
if(!logFp) {
fprintf(stderr, "Can't open log file %s.\n", logName);
coverError(SEE_ABOVE_ERROR);
}
if(verbose && !pdoFlag){
printParams(stdout);
}
printParams(logFp);
}

void printProblemOutput(){
if(verbose){
printf("Result:\n" "-------\n"
"EndLimit = %d\n\n", endLimit);
}
if(verbose){
if(finalCost <= endLimit) {
printf("Solution:\n" "---------\n");
} else {
printf("EndLimit was not reached.\n\n");
if(verbose >= 2) {
printf("Inadequate solution:\n" "--------------------\n");
printSolution(stdout);
}
}
}
if(finalCost <= endLimit) {
if(verbose) {
printSolution(stdout);
}
if(pack){
asprintf(&resultName, "./solutions/P(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b);
}else{
asprintf(&resultName, "./solutions/C(%d,%d,%d,%d,%d) - %d.res", v,k,m,t,coverNumber,b);
}
resFp = fopen(resultName, "w");
if(!resFp) {
fprintf(stderr, "Can't open file %s.\n", resultName);
coverError(SEE_ABOVE_ERROR);
}
printSolution(resFp);
fclose(resFp);
}
}
4 changes: 2 additions & 2 deletions cover.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

#include <stdio.h>
#include <limits.h>

#include <cstdlib>
//#define maxv 40
#define maxv 70
/* binomial coefficients are tried to calculate up to binCoef[maxv][?]
* (overflow is checked and the program is not halted
*/

#define min(X,Y) ((X) < (Y) ? (X) : (Y))
//#define min(X,Y) ((X) < (Y) ? (X) : (Y))


/* initialize random number generator */
Expand Down
Loading