more stricter renaming in swig files to follow language naming convention

This commit is contained in:
lperron@google.com
2012-01-21 17:15:03 +00:00
parent 1a05d382dd
commit ddae0d3014
153 changed files with 1392 additions and 1354 deletions

View File

@@ -1,16 +1,16 @@
# Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
@@ -18,20 +18,20 @@
http://en.wikipedia.org/wiki/Nonogram
'''
Nonograms or Paint by Numbers are picture logic puzzles in which cells in a
grid have to be colored or left blank according to numbers given at the
side of the grid to reveal a hidden picture. In this puzzle type, the
numbers measure how many unbroken lines of filled-in squares there are
in any given row or column. For example, a clue of '4 8 3' would mean
there are sets of four, eight, and three filled squares, in that order,
Nonograms or Paint by Numbers are picture logic puzzles in which cells in a
grid have to be colored or left blank according to numbers given at the
side of the grid to reveal a hidden picture. In this puzzle type, the
numbers measure how many unbroken lines of filled-in squares there are
in any given row or column. For example, a clue of '4 8 3' would mean
there are sets of four, eight, and three filled squares, in that order,
with at least one blank square between successive groups.
'''
See problem 12 at http://www.csplib.org/.
http://www.puzzlemuseum.com/nonogram.htm
Haskell solution:
http://twan.home.fmf.nl/blog/haskell/Nonograms.details
@@ -44,7 +44,7 @@
was a major influence when writing this Google CP solver model.
I have also blogged about the development of a Nonogram solver in Comet
using the regular constraint.
using the regular constraint.
* 'Comet: Nonogram improved: solving problem P200 from 1:30 minutes
to about 1 second'
http://www.hakank.org/constraint_programming_blog/2009/03/comet_nonogram_improved_solvin_1.html
@@ -54,15 +54,15 @@
http://www.hakank.org/constraint_programming_blog/2009/02/comet_regular_constraint_a_muc_1.html
Compare with the other models:
* Gecode/R: http://www.hakank.org/gecode_r/nonogram.rb (using 'regexps')
* Gecode/R: http://www.hakank.org/gecode_r/nonogram.rb (using 'regexps')
* MiniZinc: http://www.hakank.org/minizinc/nonogram_regular.mzn
* MiniZinc: http://www.hakank.org/minizinc/nonogram_create_automaton.mzn
* MiniZinc: http://www.hakank.org/minizinc/nonogram_create_automaton.mzn
* MiniZinc: http://www.hakank.org/minizinc/nonogram_create_automaton2.mzn
Note: nonogram_create_automaton2.mzn is the preferred model
This model was created by Hakan Kjellerstrand (hakank@bonetmail.com)
Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/
"""
import sys
@@ -73,7 +73,7 @@ from constraint_solver import pywrapcp
#
# Global constraint regular
#
# This is a translation of MiniZinc's regular constraint (defined in
# This is a translation of MiniZinc's regular constraint (defined in
# lib/zinc/globals.mzn), via the Comet code refered above.
# All comments are from the MiniZinc code.
# '''
@@ -93,7 +93,7 @@ from constraint_solver import pywrapcp
def regular(x, Q, S, d, q0, F):
solver = x[0].solver()
assert Q > 0, 'regular: "Q" must be greater than zero'
assert S > 0, 'regular: "S" must be greater than zero'
@@ -101,7 +101,7 @@ def regular(x, Q, S, d, q0, F):
# each possible input; each extra transition is from state zero
# to state zero. This allows us to continue even if we hit a
# non-accepted input.
# int d2[0..Q, 1..S]
d2 = []
for i in range(Q+1):
@@ -122,29 +122,29 @@ def regular(x, Q, S, d, q0, F):
x_range = range(0,len(x))
m = 0
n = len(x)
a = [solver.IntVar(0, Q+1, 'a[%i]' % i) for i in range(m, n+1)]
# Check that the final state is in F
solver.Add(solver.MemberCt(a[-1], F))
# First state is q0
solver.Add(a[m] == q0)
solver.Add(a[m] == q0)
for i in x_range:
solver.Add(x[i] >= 1)
solver.Add(x[i] <= S)
# Determine a[i+1]: a[i+1] == d2[a[i], x[i]]
solver.Add(a[i+1] == solver.Element(d2_flatten, ((a[i])*S)+(x[i]-1)))
#
# Make a transition (automaton) matrix from a
# single pattern, e.g. [3,2,1]
#
def make_transition_matrix(pattern):
p_len = len(pattern)
num_states = p_len + sum(pattern)
# this is for handling 0-clues. It generates
# just the state 1,2
if num_states == 0:
@@ -156,7 +156,7 @@ def make_transition_matrix(pattern):
for j in range(2):
row.append(0)
t_matrix.append(row)
# convert pattern to a 0/1 pattern for easy handling of
# the states
tmp = [0 for i in range(num_states)]
@@ -172,7 +172,7 @@ def make_transition_matrix(pattern):
t_matrix[num_states-1][0] = num_states
t_matrix[num_states-1][1] = 0
for i in range(num_states):
if tmp[i] == 0:
t_matrix[i][0] = i+1
@@ -191,7 +191,7 @@ def make_transition_matrix(pattern):
# for i in range(num_states):
# for j in range(2):
# print t_matrix[i][j],
# print
# print
# print
return t_matrix
@@ -202,7 +202,7 @@ def make_transition_matrix(pattern):
#
def check_rule(rules, y):
solver = y[0].solver()
r_len = sum([1 for i in range(len(rules)) if rules[i] > 0])
rules_tmp = []
for i in range(len(rules)):
@@ -224,7 +224,7 @@ def check_rule(rules, y):
def main(rows, row_rule_len, row_rules,
cols, col_rule_len, col_rules):
# Create the solver.
solver = pywrapcp.Solver('Regular test')
@@ -250,11 +250,11 @@ def main(rows, row_rule_len, row_rules,
for j in range(cols):
board_label.append(board[i,j])
else:
for j in range(cols):
for j in range(cols):
for i in range(rows):
board_label.append(board[i,j])
#
# constraints
#
@@ -266,19 +266,19 @@ def main(rows, row_rule_len, row_rules,
check_rule([col_rules[j][k] for k in range(col_rule_len)],
[board[i,j] for i in range(rows)])
#
# solution and search
#
db = solver.Phase(board_label,
solver.CHOOSE_FIRST_UNBOUND,
solver.CHOOSE_FIRST_UNBOUND,
solver.ASSIGN_MIN_VALUE)
solver.NewSearch(db)
num_solutions = 0
while solver.NextSolution():
print
print
num_solutions += 1
for i in range(rows):
row = [board[i,j].Value()-1 for j in range(cols)]
@@ -289,20 +289,20 @@ def main(rows, row_rule_len, row_rules,
else:
row_pres.append(' ')
print ' ', ''.join(row_pres)
print
print ' ', '-' * cols
if num_solutions >= 2:
print '2 solutions is enough...'
break
solver.EndSearch()
print
print 'num_solutions:', num_solutions
print 'failures:', solver.failures()
print 'branches:', solver.branches()
print 'wall_time:', solver.wall_time(), 'ms'
print 'failures:', solver.Failures()
print 'branches:', solver.Branches()
print 'WallTime:', solver.WallTime(), 'ms'