-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
429cab2
commit 9d30fb3
Showing
10 changed files
with
189 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
<CodeBlocks_project_file> | ||
<FileVersion major="1" minor="6" /> | ||
<Project> | ||
<Option title="DP3UKInstance" /> | ||
<Option pch_mode="2" /> | ||
<Option compiler="gcc_v83" /> | ||
<Build> | ||
<Target title="Debug"> | ||
<Option output="../../bin/DP3UKInstance" prefix_auto="1" extension_auto="1" /> | ||
<Option object_output="obj/Debug/" /> | ||
<Option type="1" /> | ||
<Option compiler="gcc_v83" /> | ||
<Option parameters="C:\Users\James\code\knapsack\data\gcut\item4cube_bin13cube.txt" /> | ||
<Compiler> | ||
<Add option="-g" /> | ||
</Compiler> | ||
</Target> | ||
<Target title="Release"> | ||
<Option output="../../bin/DP3UKInstance" prefix_auto="1" extension_auto="1" /> | ||
<Option object_output="obj/Release/" /> | ||
<Option type="1" /> | ||
<Option compiler="gcc_v83" /> | ||
<Compiler> | ||
<Add option="-O2" /> | ||
</Compiler> | ||
<Linker> | ||
<Add option="-s" /> | ||
</Linker> | ||
</Target> | ||
</Build> | ||
<Compiler> | ||
<Add option="-Wall" /> | ||
<Add option="-fexceptions" /> | ||
<Add option="-std=c++17" /> | ||
</Compiler> | ||
<Linker> | ||
<Add option="-static-libstdc++" /> | ||
<Add option="-static-libgcc" /> | ||
<Add option="-static" /> | ||
</Linker> | ||
<Unit filename="../../src/DDP.cpp" /> | ||
<Unit filename="../../src/DP3UK.cpp" /> | ||
<Unit filename="../../src/DP3UKInstance.cpp" /> | ||
<Unit filename="../../src/RRP.cpp" /> | ||
<Unit filename="../../src/knapsack.h" /> | ||
<Unit filename="../../src/sInstance.cpp" /> | ||
<Extensions> | ||
<code_completion /> | ||
<envvars /> | ||
<debugger /> | ||
<lib_finder disable_auto="1" /> | ||
</Extensions> | ||
</Project> | ||
</CodeBlocks_project_file> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1 | ||
13 13 13 | ||
4 4 4 | ||
item4cube_bin13cube |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#include <vector> | ||
|
||
#include <iostream> | ||
|
||
std::vector<int> DDP( | ||
int D, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** Application to read THREE-DIMENSIONAL UNBOUNDED KNAPSACK PROBLEM - INSTANCES | ||
from http://www.loco.ic.unicamp.br/files/instances/3duk/ | ||
apply code Implemented from the psuedo code in | ||
Cintra GF, Miyazawa FK, Wakabayashi Y, Xavier EC. Algorithms for twodimensional cutting stock and strip packing problems using dynamic programming and column generation. European Journal of Operational Research | ||
2008;191:59–83 | ||
algorithm 1: DP3UK | ||
*/ | ||
|
||
|
||
#include <iostream> | ||
#include <vector> | ||
#include "knapsack.h" | ||
|
||
|
||
int main( int argc, char* argv[] ) | ||
{ | ||
std::cout << "DP3UK\n"; | ||
|
||
if( argc != 2 ) | ||
{ | ||
std::cout << "Usage: DP3UKInstance <path to instance file>\n"; | ||
exit(1); | ||
} | ||
|
||
// read the instance file | ||
sInstance problem; | ||
problem.read( argv[1] ); | ||
|
||
// run the algorithm | ||
auto P = DP3UK( problem ); | ||
|
||
// display the solution | ||
std::cout << P.text() << "\n"; | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <fstream> | ||
#include <sstream> | ||
#include <iostream> | ||
#include "knapsack.h" | ||
|
||
std::vector< int > | ||
ParseSpaceDelimited( | ||
const std::string& l ) | ||
{ | ||
std::vector< int > output; | ||
std::stringstream sst(l); | ||
std::string a; | ||
while( getline( sst, a, ' ' ) ) | ||
output.push_back( atoi(a.c_str())); | ||
return output; | ||
} | ||
|
||
void sInstance::read( const std::string& fname ) | ||
{ | ||
std::ifstream f( fname ); | ||
if( ! f.is_open() ) | ||
throw std::runtime_error("Cannot read instance file " + fname ); | ||
|
||
l.clear(); | ||
w.clear(); | ||
h.clear(); | ||
|
||
int box_type_count; | ||
int lcount = 0; | ||
std::string line; | ||
while( std::getline( f, line ) ) | ||
{ | ||
//std::cout << lcount << " " << line << "\n"; | ||
if( lcount == 0 ) | ||
{ | ||
box_type_count = atoi( line.c_str() ); | ||
lcount++; | ||
continue; | ||
} | ||
if( lcount == 1 ) | ||
{ | ||
bin = ParseSpaceDelimited( line ); | ||
lcount++; | ||
continue; | ||
} | ||
if( lcount < 2 + box_type_count ) | ||
{ | ||
auto lv = ParseSpaceDelimited( line ); | ||
l.push_back( lv[0] ); | ||
w.push_back( lv[1] ); | ||
h.push_back( lv[2] ); | ||
item_values.push_back( lv[0]*lv[1]*lv[2] ); | ||
lcount++; | ||
continue; | ||
} | ||
myName = line; | ||
} | ||
std::cout << "read problem " << myName << "\n"; | ||
} | ||
|
||
std::string sInstance::text() | ||
{ | ||
std::stringstream ss; | ||
for( int k = 0; k < (int)l.size(); k++ ) | ||
ss << l[k] <<" "<< w[k] <<" " << h[k] << "\n"; | ||
return ss.str(); | ||
} |