Generate dynamic programming code from given state translation equation
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
.travis.yml
LICENSE
README.md
install.bat
install.sh
samples.txt

README.md

Gen4DP

Build Status

This is a simple program which generates C++ dynamic programming code from given state-translation equation.

Unit tests are included.

Example

for the input:

dp[full] -> dp[full - 1] + dp[full - 2] (full >= 2)
	 -> 1 (full == 1 or full == 2)
	 -> 0 (else)

It generates:

/// Generated by Gen4DP at: Tue Jan  3 17:03:42 CST 2017
/// Language: C++
/// This open source generator is under GNU General Public License v3.0.
/// Source: https://github.com/ice1000/Gen4DP
#include <iostream>
#include <algorithm>
using namespace std;
const int SIZE=101;
typedef int number;
number dp[SIZE];

int main(const int argc, const char *argv[]) {
	int full,full_len;
	cin>>full_len;
	for (full=0; full<=full_len; ++full) {
		if (full>=2) {
			dp[full] = dp[full-1]+dp[full-2];
		}
		else if (full==1||full==2) {
			dp[full] = 1;
		}
		else {
			dp[full] = 0;
		}
	}
	cout<<dp[full_len]<<endl;
	return 0;
}

If the equation has two dimensions:

a[i, j]-> a[i - 1, j] + a[i, j - 1] (i >= 1 and j >= 1)
       -> 1 (else)

It generates:

/// Generated by Gen4DP at: Tue Jan  3 17:22:25 CST 2017
/// Language: C++
/// This open source generator is under GNU General Public License v3.0.
/// Source: https://github.com/ice1000/Gen4DP
#include <iostream>
#include <algorithm>
using namespace std;
const int SIZE=101;
typedef int number;
number a[SIZE][SIZE];

int main(const int argc, const char *argv[]) {
	int i,j,i_len,j_len;
	cin>>i_len>>j_len;
	for (i=0; i<=i_len; ++i) {
		for (j=0; j<=j_len; ++j) {
			if (i>=1&&j>=1) {
				a[i][j] = a[i-1][j]+a[i][j-1];
			}
			else {
				a[i][j] = 1;
			}
		}
	}
	cout<<a[i_len][j_len]<<endl;
	return 0;
}

It will also give you error messages, like 'braces don't match', 'invalid naming', etc.