text:
#include <list>
#include <string>
#include <iostream>
#include <boost/lambda/bind.hpp>
#include "loggerout.h"
#include "baselogger.h"
#include "filelogger.h"
#include "consolelogger.h"
#include "commonlogger.h"
#include "nulllogger.h"
#include "../dispatcher/logdispatcher.h"
#include "../utils.h"

namespace piel { namespace lib { namespace logger_out {

using namespace piel::lib::logger;
using namespace piel::lib::logger_utils;

const char* LoggerOut::time_format = "%Y-%m-%d %I:%M:%S";
LogPtr LoggerOut::common_logger_(new CommonLogger());

LoggerOut::LoggerOut()
    : qthread_(QueuedThread<logger::LogMessage>::start())
{
    qthread_->on_message.connect(boost::bind(&LoggerOut::on_message, this, _1));
}

LoggerOut::~LoggerOut()
{
    qthread_->enqueue(logger::LogMessage(logger::QUIT));
    qthread_->join();
}

void LoggerOut::enqueue(const logger::LogMessage& v)
{
    qthread_->enqueue(v);
}

void LoggerOut::gen_message(logger::LogMessage& m)
{
    std::stringstream os;

    if (enable_logs_timestamps_) {
        os << "[" << time_to_str(time_format) << "]";
    }
    os << "[" << m.name << "][" << BaseLogger::get_log_type_str(m.type) << "] " << m.message;

    m.message = os.str();
}

void LoggerOut::create_log(const std::string& _name)
{
    std::string nName = normalize(_name);
    {
        LogPtr log {new NullLogger(_name)};
        log_ptr_list_.push_back(log);
    }

    if (!get_env(nName + ConsoleLogger::sfx, false) ||
         get_env(BaseLogger::default_logger + ConsoleLogger::sfx, true) ) {
        LogPtr log {new ConsoleLogger(_name)};
        log_ptr_list_.push_back(log);
    }

    if (!get_env(FileLogger::default_logger_filename, std::string("")).empty()) {
        if (get_env(nName + FileLogger::sfx, false) ||
            get_env(BaseLogger::default_logger + FileLogger::sfx, false)) {
            LogPtr log {new FileLogger(_name)};
            log_ptr_list_.push_back(log);

        }
    }

    enable_logs_timestamps_ = get_env(BaseLogger::default_logger + BaseLogger::timestamps_sfx, false);
}

void LoggerOut::remove_log(const std::string& _name)
{
    log_ptr_list_.remove_if(std::bind2nd(CheckEqualLog(), _name));
    log_ptr_list_.remove_if(std::bind2nd(CheckEqualLog(), _name+"_null"));
}

void LoggerOut::print(const logger::LogMessage& m)
{
    logger::LogMessage new_m(m);
    gen_message(new_m);

    for(LogPtrList::const_iterator i=log_ptr_list_.begin(), end = log_ptr_list_.end(); i!=end; ++i) {
        if ( (*i)->get_mame() != m.name ) continue;
        (*i)->print_message(new_m);
    }
}

int LoggerOut::on_message(const logger::LogMessage& m)
{
    int retVal = 0;
    switch (m.cmd) {
    case logger::LOG:
        print(m);
        break;
    case logger::CREATE_LOG:
        create_log(m.name);
        break;
    case logger::REMOVE_LOG:
        remove_log(m.name);
        break;
    case logger::QUIT:
        retVal = -1;
        break;
    default:
        break;
    }
    return retVal;
}

logger::LogPtr LoggerOut::common_logger()
{
    return common_logger_;
}

} } } // namespace piel::lib::logger_out

ext: cpp

max_stars_repo_name: diakovliev/pie

max_issues_repo_name: diakovliev/pie

max_forks_repo_name: diakovliev/pie


text:
/*********************************************************************
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2013, Ioan A. Sucan
 *  Copyright (c) 2016, Robert Haschke
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the names of the authors nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *********************************************************************/

/* Author: Ioan Sucan, Robert Haschke */

#include "moveit_fake_controllers.h"
#include <ros/param.h>
#include <sensor_msgs/JointState.h>
#include <boost/thread.hpp>
#include <limits>

namespace moveit_fake_controller_manager
{
BaseFakeController::BaseFakeController(const std::string& name, const std::vector<std::string>& joints,
                                       const ros::Publisher& pub)
  : moveit_controller_manager::MoveItControllerHandle(name), joints_(joints), pub_(pub)
{
  std::stringstream ss;
  ss << "Fake controller '" << name << "' with joints [ ";
  std::copy(joints.begin(), joints.end(), std::ostream_iterator<std::string>(ss, " "));
  ss << "]";
  ROS_INFO_STREAM(ss.str());
}

void BaseFakeController::getJoints(std::vector<std::string>& joints) const
{
  joints = joints_;
}

moveit_controller_manager::ExecutionStatus BaseFakeController::getLastExecutionStatus()
{
  return moveit_controller_manager::ExecutionStatus::SUCCEEDED;
}

LastPointController::LastPointController(const std::string& name, const std::vector<std::string>& joints,
                                         const ros::Publisher& pub)
  : BaseFakeController(name, joints, pub)
{
}

LastPointController::~LastPointController() = default;

bool LastPointController::sendTrajectory(const moveit_msgs::RobotTrajectory& t)
{
  ROS_INFO("Fake execution of trajectory");
  if (t.joint_trajectory.points.empty())
    return true;

  sensor_msgs::JointState js;
  const trajectory_msgs::JointTrajectoryPoint& last = t.joint_trajectory.points.back();
  js.header = t.joint_trajectory.header;
  js.header.stamp = ros::Time::now();
  js.name = t.joint_trajectory.joint_names;
  js.position = last.positions;
  js.velocity = last.velocities;
  js.effort = last.effort;
  pub_.publish(js);

  return true;
}

bool LastPointController::cancelExecution()
{
  return true;
}

bool LastPointController::waitForExecution(const ros::Duration& /*timeout*/)
{
  ros::Duration(0.5).sleep();  // give some time to receive the published JointState
  return true;
}

ThreadedController::ThreadedController(const std::string& name, const std::vector<std::string>& joints,
                                       const ros::Publisher& pub)
  : BaseFakeController(name, joints, pub)
{
}

ThreadedController::~ThreadedController()
{
  ThreadedController::cancelTrajectory();
}

void ThreadedController::cancelTrajectory()
{
  cancel_ = true;
  thread_.join();
}

bool ThreadedController::sendTrajectory(const moveit_msgs::RobotTrajectory& t)
{
  cancelTrajectory();  // cancel any previous fake motion
  cancel_ = false;
  status_ = moveit_controller_manager::ExecutionStatus::PREEMPTED;
  thread_ = boost::thread(boost::bind(&ThreadedController::execTrajectory, this, t));
  return true;
}

bool ThreadedController::cancelExecution()
{
  cancelTrajectory();
  ROS_INFO("Fake trajectory execution cancelled");
  status_ = moveit_controller_manager::ExecutionStatus::ABORTED;
  return true;
}

bool ThreadedController::waitForExecution(const ros::Duration& /*timeout*/)
{
  thread_.join();
  status_ = moveit_controller_manager::ExecutionStatus::SUCCEEDED;
  return true;
}

moveit_controller_manager::ExecutionStatus ThreadedController::getLastExecutionStatus()
{
  return status_;
}

ViaPointController::ViaPointController(const std::string& name, const std::vector<std::string>& joints,
                                       const ros::Publisher& pub)
  : ThreadedController(name, joints, pub)
{
}

ViaPointController::~ViaPointController() = default;

void ViaPointController::execTrajectory(const moveit_msgs::RobotTrajectory& t)
{
  ROS_INFO("Fake execution of trajectory");
  sensor_msgs::JointState js;
  js.header = t.joint_trajectory.header;
  js.name = t.joint_trajectory.joint_names;

  // publish joint states for all intermediate via points of the trajectory
  // no further interpolation
  ros::Time startTime = ros::Time::now();
  for (std::vector<trajectory_msgs::JointTrajectoryPoint>::const_iterator via = t.joint_trajectory.points.begin(),
                                                                          end = t.joint_trajectory.points.end();
       !cancelled() && via != end; ++via)
  {
    js.position = via->positions;
    js.velocity = via->velocities;
    js.effort = via->effort;

    ros::Duration waitTime = via->time_from_start - (ros::Time::now() - startTime);
    if (waitTime.toSec() > std::numeric_limits<float>::epsilon())
    {
      ROS_DEBUG("Fake execution: waiting %0.1fs for next via point, %ld remaining", waitTime.toSec(), end - via);
      waitTime.sleep();
    }
    js.header.stamp = ros::Time::now();
    pub_.publish(js);
  }
  ROS_DEBUG("Fake execution of trajectory: done");
}

InterpolatingController::InterpolatingController(const std::string& name, const std::vector<std::string>& joints,
                                                 const ros::Publisher& pub)
  : ThreadedController(name, joints, pub), rate_(10)
{
  double r;
  if (ros::param::get("~fake_interpolating_controller_rate", r))
    rate_ = ros::WallRate(r);
}

InterpolatingController::~InterpolatingController() = default;

namespace
{
void interpolate(sensor_msgs::JointState& js, const trajectory_msgs::JointTrajectoryPoint& prev,
                 const trajectory_msgs::JointTrajectoryPoint& next, const ros::Duration& elapsed)
{
  double duration = (next.time_from_start - prev.time_from_start).toSec();
  double alpha = 1.0;
  if (duration > std::numeric_limits<double>::epsilon())
    alpha = (elapsed - prev.time_from_start).toSec() / duration;

  js.position.resize(prev.positions.size());
  for (std::size_t i = 0, end = prev.positions.size(); i < end; ++i)
  {
    js.position[i] = prev.positions[i] + alpha * (next.positions[i] - prev.positions[i]);
  }
}
}  // namespace

void InterpolatingController::execTrajectory(const moveit_msgs::RobotTrajectory& t)
{
  ROS_INFO("Fake execution of trajectory");
  if (t.joint_trajectory.points.empty())
    return;

  sensor_msgs::JointState js;
  js.header = t.joint_trajectory.header;
  js.name = t.joint_trajectory.joint_names;

  const std::vector<trajectory_msgs::JointTrajectoryPoint>& points = t.joint_trajectory.points;
  std::vector<trajectory_msgs::JointTrajectoryPoint>::const_iterator prev = points.begin(),  // previous via point
      next = points.begin() + 1,  // currently targetted via point
      end = points.end();

  ros::Time startTime = ros::Time::now();
  while (!cancelled())
  {
    ros::Duration elapsed = ros::Time::now() - startTime;
    // hop to next targetted via point
    while (next != end && elapsed > next->time_from_start)
    {
      ++prev;
      ++next;
    }
    if (next == end)
      break;

    double duration = (next->time_from_start - prev->time_from_start).toSec();
    ROS_DEBUG("elapsed: %.3f via points %td,%td / %td  alpha: %.3f", elapsed.toSec(), prev - points.begin(),
              next - points.begin(), end - points.begin(),
              duration > std::numeric_limits<double>::epsilon() ? (elapsed - prev->time_from_start).toSec() / duration :
                                                                  1.0);
    interpolate(js, *prev, *next, elapsed);
    js.header.stamp = ros::Time::now();
    pub_.publish(js);
    rate_.sleep();
  }
  if (cancelled())
    return;

  ros::Duration elapsed = ros::Time::now() - startTime;
  ROS_DEBUG("elapsed: %.3f via points %td,%td / %td  alpha: 1.0", elapsed.toSec(), prev - points.begin(),
            next - points.begin(), end - points.begin());

  // publish last point
  interpolate(js, *prev, *prev, prev->time_from_start);
  js.header.stamp = ros::Time::now();
  pub_.publish(js);

  ROS_DEBUG("Fake execution of trajectory: done");
}

}  // end namespace moveit_fake_controller_manager

max_stars_repo_name: tsijs/moveit

max_issues_repo_name: tsijs/moveit

max_forks_repo_name: tsijs/moveit


text:
//****************************************************************************
// (c) 2008 by the openOR Team
//****************************************************************************
// The contents of this file are available under the GPL v2.0 license
// or under the openOR comercial license. see
//   /Doc/openOR_free_license.txt or
//   /Doc/openOR_comercial_license.txt
// for Details.
//****************************************************************************
//! OPENOR_INTERFACE_FILE(Image_ImageData)
//****************************************************************************

/**
 * @file
 * @author Christian Winne
 * \ingroup Image_ImageData
 */
#ifndef openOR_Image_Image2DData_hpp
#define openOR_Image_Image2DData_hpp

#include <cassert>
#include <memory>

#include <openOR/coreDefs.hpp>

//#include <boost/config.hpp>
#include <boost/type_traits/has_trivial_destructor.hpp>
#include <boost/type_traits/has_trivial_assign.hpp>

#include <openOR/Math/vector.hpp>
#include <openOR/Math/vectorfunctions.hpp>
#include <openOR/Math/create.hpp>
#include <openOR/Utility/Types.hpp>
#include <openOR/Image/Image2DSize.hpp>
#include <openOR/Image/Image2DRawData.hpp>
#include <openOR/OpenGL/DataInterpreter.hpp>

namespace openOR
{
   namespace Image
   {

     /** A class, that holds image data and provides methods for accessing.
      *
      * ImageElements will be initialized by a given value or by default by a construction from zero. That means the
      * given type for VolumeElements (Type) must have an explicit public constructor from int, that constructs an initialized
      * instance (e.g. MyVoxelElementType(int val))
      *
      * @param Type Type of volume element.
      * @param Alloc Type of allocator for element memory allocation.
      *
      * @author Christian Winne
      *
      * @bug -clipping of SamplingRegion at ConstMMIterator constructor does not work correctly
      *
      * @todo -documentation
      *       -testcases
      *
      * @ingroup Image_ImageData
      */
     template<class Type, class Alloc = std::allocator<Type> >
     class Image2DData : public Image2DSize, public Image2DRawData<Type>, public OpenGL::DataInterpreter
     {
       public:

         typedef typename Alloc::template rebind<Type>::other AllocatorType;
         typedef typename AllocatorType::pointer _pointerType;
         typedef typename AllocatorType::pointer Pointer;
         typedef typename AllocatorType::const_pointer ConstPointer;
         typedef typename AllocatorType::reference _referenceType;
         typedef typename AllocatorType::reference Reference;
         typedef typename AllocatorType::const_reference ConstReference;
         typedef typename AllocatorType::value_type ValueType;
         typedef typename AllocatorType::size_type SizeType;
         typedef typename AllocatorType::difference_type DifferenceType;

         Image2DData()
         : m_pData(NULL),
           m_OpenGLDataFormat(OpenGL::getOpenGLDataFormatFromElementType<Type>()),
           m_OpenGLDataType(OpenGL::getOpenGLDataTypeFromElementType<Type>())
         {
           m_sizeImage(0) = 0;
           m_sizeImage(1) = 0;
           m_sizeMMImage(0) = 1;
           m_sizeMMImage(1) = 1;
         }

         /**
          * Destructor. Frees the memory used by internal data.
          */
         virtual ~Image2DData()
         {
           if (m_pData)
           {
             destroyData(boost::has_trivial_destructor<Type>());
             m_Allocator.deallocate(m_pData, m_sizeImage(0) * m_sizeImage(1));
           }
         }

         virtual void setSize(const Math::Vector2ui& sizeImage)
         {
            setSize(sizeImage, Type());
         }

         void setSize(const Math::Vector2ui& sizeImage, const Type& initializeValue)
         {
           if (m_pData)
           {
             SizeType size = m_sizeImage(0) * m_sizeImage(1);
             m_Allocator.deallocate(m_pData, size);
             m_pData = NULL;
           }

           m_sizeImage = sizeImage;
           SizeType size = m_sizeImage(0) * m_sizeImage(1);
           if (size > 0)
           {
             Pointer p = m_pData = m_Allocator.allocate(size);
             std::uninitialized_fill(p, p + size, initializeValue);
           }
         }

         virtual Math::Vector2ui size() const { return m_sizeImage; }

         virtual void setSizeMM(const Math::Vector2d& sizeMMImage) { m_sizeMMImage = sizeMMImage; }

         virtual Math::Vector2d sizeMM() const { return m_sizeMMImage; }

         virtual const void* dataPtr() const { return static_cast<const void*>(data()); }
         virtual void* mutableDataPtr() { return static_cast<void*>(mutableData()); }

         virtual const void* dataPtr(const Math::Vector2ui& indexPos) const { return static_cast<const void*>(data() + indexPos(0) + m_sizeImage(0) * indexPos(1));  }
         virtual void* mutableDataPtr(const Math::Vector2ui& indexPos) { return static_cast<void*>(mutableData() + indexPos(0) + m_sizeImage(0) * indexPos(1));  }

         virtual const unsigned int dataFormat() const { return m_OpenGLDataFormat; }
         virtual void setDataFormat(unsigned int nDataFormat) { m_OpenGLDataFormat = nDataFormat; }
         virtual const unsigned int dataType() const { return m_OpenGLDataType; }
         virtual void setDataType(unsigned int nDataType) { m_OpenGLDataType = nDataType; }

         /**
          * Getter for direct access to voxel data.
          * @return   A pointer to the first object of the voxel data
          */
         virtual Type* mutableData() { return m_pData; }
         virtual const Type* data() const { return m_pData; }

         AllocatorType allocator() const { return m_Allocator; }

       protected:

         void destroyData(const boost::mpl::true_&) {}

         void destroyData(const boost::mpl::false_&) {

           for ( Pointer   p = m_pData,
                           pEnd = p + Math::multipliedElements(m_sizeImage);
                 p != pEnd; ++p)
           {
             m_Allocator.destroy(p);
           }
         }

         Math::Vector2ui m_sizeImage;
         Math::Vector2d m_sizeMMImage;
         Pointer m_pData;
         AllocatorType m_Allocator;
         unsigned int m_OpenGLDataFormat;
         unsigned int m_OpenGLDataType;

      };

      // some probably often used specialized types
      typedef Image2DData<bool, std::allocator<bool> > Image2DDataBool;
      typedef Image2DData<uint8, std::allocator<uint8> > Image2DDataUI8;
      typedef Image2DData<openOR::UI8Triple, std::allocator<openOR::UI8Triple> > Image2DDataUI8Triple;
      typedef Image2DData<uint16, std::allocator<uint16> > Image2DDataUI16;
      typedef Image2DData<uint32, std::allocator<uint32> > Image2DDataUI32;
      typedef Image2DData<uint, std::allocator<uint> > Image2DDataUI;
      typedef Image2DData<float, std::allocator<float> > Image2DDataFloat;
      typedef Image2DData<double, std::allocator<double> > Image2DDataDouble;
      typedef Image2DData<FloatQuad, std::allocator<FloatQuad> > Image2DDataFloatQuad;

      typedef Image2DData<UI16Pair, std::allocator<UI16Pair> > Image2DDataUI16Pair;
   }
}

#endif

ext: hpp

max_stars_repo_name: avinfinity/UnmanagedCodeSnippets

max_issues_repo_name: avinfinity/UnmanagedCodeSnippets

max_forks_repo_name: avinfinity/UnmanagedCodeSnippets


text:
//          Copyright John W. Wilkinson 2007 - 2013
// Distributed under the MIT License, see accompanying file LICENSE.txt

// json spirit version 4.06.1
// upstream json spirit version 4.06

#include "json_spirit_writer_test.h"
#include "utils_test.h"
#include "json_spirit_writer.h"
#include "json_spirit_value.h"

#include <sstream>
#include <boost/integer_traits.hpp>

using namespace json_spirit;
using namespace std;
using namespace boost;

namespace
{
    const int64_t max_int64   = integer_traits< int64_t  >::max();
    const uint64_t max_uint64 = integer_traits< uint64_t >::max();

    template< class Config_type >
    struct Test_runner
    {
        typedef typename Config_type::String_type String_type;
        typedef typename Config_type::Object_type Object_type;
        typedef typename Config_type::Array_type Array_type;
        typedef typename Config_type::Value_type Value_type;
        typedef typename String_type::value_type Char_type;
        typedef typename String_type::const_iterator Iter_type;
        typedef std::basic_ostream< Char_type > Ostream_type;

        String_type to_str( const char* c_str )
        {
            return ::to_str< String_type >( c_str );
        }

        String_type zero_str()
        {
#ifdef WIN32
            return to_str( "0.00000000000000000" );
#else
            return to_str( "0.0000000000000000" );
#endif
        }

        void add_value( Object_type& obj, const char* c_name, const Value_type& value )
        {
            Config_type::add( obj, to_str( c_name ), value );
        }

        void add_c_str( Object_type& obj, const char* c_name, const char* c_value )
        {
            add_value( obj, c_name, to_str( c_value ) );
        }

        void check_eq( const Value_type& value, const String_type& expected_result )
        {
           assert_eq( write( value ), expected_result );
        }

        void check_eq( const Value_type& value, const char* expected_result )
        {
           check_eq( value, to_str( expected_result ) );
        }

        void check_eq_pretty( const Value_type& value, const char* expected_result )
        {
            assert_eq( write_formatted( value ), to_str( expected_result ) );
            assert_eq( write( value, pretty_print ), to_str( expected_result ) );
        }

        void check_eq_single_line_arrays( const Value_type& value, const char* expected_result )
        {
            assert_eq( write( value, single_line_arrays ), to_str( expected_result ) );
        }

        void check_eq( const Value_type& value, const String_type& expected_result , unsigned int options )
        {
            assert_eq( write( value, options ), expected_result );
        }

        void check_eq( const Value_type& value, const char* expected_result, unsigned int options )
        {
            check_eq( value, to_str( expected_result ), options );
        }

        void test_empty_obj()
        {
            check_eq( Object_type(), "{}" );
            check_eq_pretty( Object_type(), "{\n}" );
        }

        void test_obj_with_one_member()
        {
            Object_type obj;

            add_c_str( obj, "name", "value" );

            check_eq       ( obj, "{\"name\":\"value\"}" );
            check_eq_pretty( obj, "{\n"
                                  "    \"name\" : \"value\"\n"
                                  "}" );
        }

        void test_obj_with_two_members()
        {
            Object_type obj;

            add_c_str( obj, "name_1", "value_1" );
            add_c_str( obj, "name_2", "value_2" );

            check_eq( obj, "{\"name_1\":\"value_1\",\"name_2\":\"value_2\"}" );

            check_eq_pretty( obj, "{\n"
                                  "    \"name_1\" : \"value_1\",\n"
                                  "    \"name_2\" : \"value_2\"\n"
                                  "}" );
        }

        void test_obj_with_three_members()
        {
            Object_type obj;

            add_c_str( obj, "name_1", "value_1" );
            add_c_str( obj, "name_2", "value_2" );
            add_c_str( obj, "name_3", "value_3" );

            check_eq( obj, "{\"name_1\":\"value_1\",\"name_2\":\"value_2\",\"name_3\":\"value_3\"}" );

            check_eq_pretty( obj, "{\n"
                                  "    \"name_1\" : \"value_1\",\n"
                                  "    \"name_2\" : \"value_2\",\n"
                                  "    \"name_3\" : \"value_3\"\n"
                                  "}" );
        }

        void test_obj_with_one_empty_child_obj()
        {
            Object_type child;

            Object_type root;

            add_value( root, "child", child );

            check_eq( root, "{\"child\":{}}" );

            check_eq_pretty( root, "{\n"
                                   "    \"child\" : {\n"
                                   "    }\n"
                                   "}" );
        }

        void test_obj_with_one_child_obj()
        {
            Object_type child;

            add_c_str( child, "name_2", "value_2" );

            Object_type root;

            add_value( root, "child", child );
            add_c_str( root, "name_1", "value_1" );

            check_eq( root, "{\"child\":{\"name_2\":\"value_2\"},\"name_1\":\"value_1\"}" );

            check_eq_pretty( root, "{\n"
                                   "    \"child\" : {\n"
                                   "        \"name_2\" : \"value_2\"\n"
                                   "    },\n"
                                   "    \"name_1\" : \"value_1\"\n"
                                   "}" );
        }

        void test_obj_with_grandchild_obj()
        {
            Object_type child_1; add_c_str( child_1, "name_1", "value_1" );
            Object_type child_2;
            Object_type child_3; add_c_str( child_3, "name_3", "value_3" );

            add_value( child_2, "grandchild", child_3 );
            add_c_str( child_2, "name_2", "value_2" );

            Object_type root;

            add_value( root, "child_1", child_1 );
            add_value( root, "child_2", child_2 );
            add_c_str( root, "name_a", "value_a" );
            add_c_str( root, "name_b", "value_b" );

            check_eq( root, "{\"child_1\":{\"name_1\":\"value_1\"},"
                            "\"child_2\":{\"grandchild\":{\"name_3\":\"value_3\"},\"name_2\":\"value_2\"},"
                            "\"name_a\":\"value_a\","
                            "\"name_b\":\"value_b\"}" );

            check_eq_pretty( root, "{\n"
                                   "    \"child_1\" : {\n"
                                   "        \"name_1\" : \"value_1\"\n"
                                   "    },\n"
                                   "    \"child_2\" : {\n"
                                   "        \"grandchild\" : {\n"
                                   "            \"name_3\" : \"value_3\"\n"
                                   "        },\n"
                                   "        \"name_2\" : \"value_2\"\n"
                                   "    },\n"
                                   "    \"name_a\" : \"value_a\",\n"
                                   "    \"name_b\" : \"value_b\"\n"
                                   "}" );
        }

        void test_objs_with_bool_pairs()
        {
            Object_type obj;

            add_value( obj, "name_1", true  );
            add_value( obj, "name_2", false );
            add_value( obj, "name_3", true  );

            check_eq( obj, "{\"name_1\":true,\"name_2\":false,\"name_3\":true}" );
        }

        void test_objs_with_int_pairs()
        {
            Object_type obj;

            add_value( obj, "name_1", 11 );
            add_value( obj, "name_2", INT_MAX );
            add_value( obj, "name_3", max_int64 );

            ostringstream os;

            os << "{\"name_1\":11,\"name_2\":" << INT_MAX << ",\"name_3\":" << max_int64 << "}";

            check_eq( obj, os.str().c_str() );
        }

        void test_objs_with_real_pairs()
        {
            Object_type obj;

            add_value( obj, "name_1", 0.0 );
            add_value( obj, "name_2", 1.234567890123456789e-108 );
            add_value( obj, "name_3", -1234567890.123456789 );
            add_value( obj, "name_4", -1.2e-126 );

            check_eq( obj, to_str( "{\"name_1\":" ) + zero_str() + to_str( ","
                           "\"name_2\":1.2345678901234567e-108,"
                           "\"name_3\":-1234567890.1234567,"
                           "\"name_4\":-1.2000000000000000e-126}" ) );
        }

        void test_objs_with_null_pairs()
        {
            Object_type obj;

            add_value( obj, "name_1", Value_type::null );
            add_value( obj, "name_2", Value_type::null );
            add_value( obj, "name_3", Value_type::null );

            check_eq( obj, "{\"name_1\":null,\"name_2\":null,\"name_3\":null}" );
        }

        void test_empty_array()
        {
            check_eq( Array_type(), "[]" );
            check_eq_pretty( Array_type(), "[\n"
                                        "]" );
            check_eq_single_line_arrays( Array_type(), "[ ]" );
        }

        void test_array_with_one_member()
        {
            Array_type arr;

            arr.push_back( to_str( "value" ) );

            check_eq       ( arr, "[\"value\"]" );
            check_eq_pretty( arr, "[\n"
                                  "    \"value\"\n"
                                  "]" );
            check_eq_single_line_arrays( arr, "[ \"value\" ]" );
        }

        void test_array_with_two_members()
        {
            Array_type arr;

            arr.push_back( to_str( "value_1" ) );
            arr.push_back( 1 );

            check_eq       ( arr, "[\"value_1\",1]" );
            check_eq_pretty( arr, "[\n"
                                  "    \"value_1\",\n"
                                  "    1\n"
                                  "]" );
            check_eq_single_line_arrays( arr, "[ \"value_1\", 1 ]" );
        }

        void test_array_with_n_members()
        {
            Array_type arr;

            arr.push_back( to_str( "value_1" ) );
            arr.push_back( 123 );
            arr.push_back( 123.456 );
            arr.push_back( true );
            arr.push_back( false );
            arr.push_back( Value_type() );

            check_eq       ( arr, "[\"value_1\",123,123.45600000000000,true,false,null]" );
            check_eq_pretty( arr, "[\n"
                                  "    \"value_1\",\n"
                                  "    123,\n"
                                  "    123.45600000000000,\n"
                                  "    true,\n"
                                  "    false,\n"
                                  "    null\n"
                                  "]" );
            check_eq_single_line_arrays( arr, "[ \"value_1\", 123, 123.45600000000000, true, false, null ]" );
        }

        void test_array_with_one_empty_child_array()
        {
            Array_type arr;

            arr.push_back( Array_type() );

            check_eq       ( arr, "[[]]" );
            check_eq_pretty( arr, "[\n"
                                  "    [\n"
                                  "    ]\n"
                                  "]" );
            check_eq_single_line_arrays( arr, "[\n"
                                              "    [ ]\n"
                                              "]" );
        }

        void test_array_with_one_child_array()
        {
            Array_type child;

            child.push_back( 2 );

            Array_type root;

            root.push_back( 1 );
            root.push_back( child );

            check_eq       ( root, "[1,[2]]" );
            check_eq_pretty( root, "[\n"
                                   "    1,\n"
                                   "    [\n"
                                   "        2\n"
                                   "    ]\n"
                                   "]" );
            check_eq_single_line_arrays( root, "[\n"
                                               "    1,\n"
                                               "    [ 2 ]\n"
                                               "]" );
        }

        void test_array_with_grandchild_array()
        {
            Array_type child_1; child_1.push_back( 11 );
            Array_type child_2; child_2.push_back( 22 );
            Array_type child_3; child_3.push_back( 33 );

            child_2.push_back( child_3 );

            Array_type root;

            root.push_back( 1);
            root.push_back( child_1 );
            root.push_back( child_2 );
            root.push_back( 2 );

            check_eq       ( root, "[1,[11],[22,[33]],2]" );
            check_eq_pretty( root, "[\n"
                                   "    1,\n"
                                   "    [\n"
                                   "        11\n"
                                   "    ],\n"
                                   "    [\n"
                                   "        22,\n"
                                   "        [\n"
                                   "            33\n"
                                   "        ]\n"
                                   "    ],\n"
                                   "    2\n"
                                   "]" );
            check_eq_single_line_arrays( root, "[\n"
                                   "    1,\n"
                                   "    [ 11 ],\n"
                                   "    [\n"
                                   "        22,\n"
                                   "        [ 33 ]\n"
                                   "    ],\n"
                                   "    2\n"
                                   "]" );
        }

        void test_array_and_objs()
        {
            Array_type a;

            a.push_back( 11 );

            Object_type obj;

            add_value( obj, "a", 1 );

            a.push_back( obj );

            check_eq       ( a, "[11,{\"a\":1}]" );
            check_eq_pretty( a, "[\n"
                                "    11,\n"
                                "    {\n"
                                "        \"a\" : 1\n"
                                "    }\n"
                                "]" );
            check_eq_single_line_arrays( a, "[\n"
                                            "    11,\n"
                                            "    {\n"
                                            "        \"a\" : 1\n"
                                            "    }\n"
                                            "]" );

            add_value( obj, "b", 2 );

            a.push_back( 22 );
            a.push_back( 33 );
            a.push_back( obj );

            check_eq       ( a, "[11,{\"a\":1},22,33,{\"a\":1,\"b\":2}]" );
            check_eq_pretty( a, "[\n"
                                "    11,\n"
                                "    {\n"
                                "        \"a\" : 1\n"
                                "    },\n"
                                "    22,\n"
                                "    33,\n"
                                "    {\n"
                                "        \"a\" : 1,\n"
                                "        \"b\" : 2\n"
                                "    }\n"
                                "]" );
            check_eq_single_line_arrays( a, "[\n"
                                            "    11,\n"
                                            "    {\n"
                                            "        \"a\" : 1\n"
                                            "    },\n"
                                            "    22,\n"
                                            "    33,\n"
                                            "    {\n"
                                            "        \"a\" : 1,\n"
                                            "        \"b\" : 2\n"
                                            "    }\n"
                                            "]" );
        }

        void test_obj_and_arrays()
        {
            Object_type obj;

            add_value( obj, "a", 1 );

            Array_type a;

            a.push_back( 11 );
            a.push_back( 12 );

            add_value( obj, "b", a );

            check_eq       ( obj, "{\"a\":1,\"b\":[11,12]}" );
            check_eq_pretty( obj, "{\n"
                                  "    \"a\" : 1,\n"
                                  "    \"b\" : [\n"
                                  "        11,\n"
                                  "        12\n"
                                  "    ]\n"
                                  "}" );
            check_eq_single_line_arrays( obj, "{\n"
                                              "    \"a\" : 1,\n"
                                              "    \"b\" : [ 11, 12 ]\n"
                                              "}" );

            a.push_back( obj );

            add_value( obj, "c", a );

            check_eq       ( obj, "{\"a\":1,\"b\":[11,12],\"c\":[11,12,{\"a\":1,\"b\":[11,12]}]}" );
            check_eq_pretty( obj, "{\n"
                                  "    \"a\" : 1,\n"
                                  "    \"b\" : [\n"
                                  "        11,\n"
                                  "        12\n"
                                  "    ],\n"
                                  "    \"c\" : [\n"
                                  "        11,\n"
                                  "        12,\n"
                                  "        {\n"
                                  "            \"a\" : 1,\n"
                                  "            \"b\" : [\n"
                                  "                11,\n"
                                  "                12\n"
                                  "            ]\n"
                                  "        }\n"
                                  "    ]\n"
                                  "}" );
            check_eq_single_line_arrays( obj, "{\n"
                                              "    \"a\" : 1,\n"
                                              "    \"b\" : [ 11, 12 ],\n"
                                              "    \"c\" : [\n"
                                              "        11,\n"
                                              "        12,\n"
                                              "        {\n"
                                              "            \"a\" : 1,\n"
                                              "            \"b\" : [ 11, 12 ]\n"
                                              "        }\n"
                                              "    ]\n"
                                              "}" );
        }

        void test_escape_char( const char* esc_str_in, const char* esc_str_out, unsigned int option = 0 )
        {
            Object_type obj;

            const string name_str( string( esc_str_in ) + "name" );

            add_value( obj, name_str.c_str(), to_str( "value" ) + to_str( esc_str_in ) );

            const string out_str( string( "{\"" ) + esc_str_out + "name\":\"value" + esc_str_out + "\"}" );

            check_eq( obj, out_str.c_str(), option );
        }

        void test_escape_chars()
        {
            test_escape_char( "\r", "\\r" );
            test_escape_char( "\n", "\\n" );
            test_escape_char( "\t", "\\t" );
            test_escape_char( "\f", "\\f" );
            test_escape_char( "\b", "\\b" );
            test_escape_char( "\"", "\\\"" );
            test_escape_char( "\\", "\\\\" );
            test_escape_char( "\x01", "\\u0001" );
            test_escape_char( "\x12", "\\u0012" );
            test_escape_char( "\x7F", "\\u007F" );
        }

        void test_disabling_nonprintable_esc_chars()
        {
            test_escape_char( "\t", "\\t", raw_utf8 );
            test_escape_char( "\x01",     "\x01", raw_utf8 );
            test_escape_char( "\x01\x12", "\x01\x12", raw_utf8 );
        }

        void test_to_stream()
        {
            basic_ostringstream< Char_type > os;

            Array_type arr;

            arr.push_back( 111 );
            arr.push_back( 222 );

            os << hex;  // the code should handle this, i.e. output decimal

            write( arr, os );

            assert_eq( os.str(), to_str( "[111,222]" ) );
        }

        void test_values()
        {
            check_eq( 123, "123" );
            check_eq( 1.234, "1.2340000000000000" );
            check_eq( to_str( "abc" ), "\"abc\"" );
            check_eq( false, "false" );
            check_eq( Value_type::null, "null" );
        }

        void test_uint64()
        {
            check_eq( Value_type( 0 ),             "0" );
            check_eq( Value_type( int64_t( 0 ) ),  "0" );
            check_eq( Value_type( uint64_t( 0 ) ), "0" );

            check_eq( Value_type( 1 ),             "1" );
            check_eq( Value_type( int64_t( 1 ) ),  "1" );
            check_eq( Value_type( uint64_t( 1 ) ), "1" );

            check_eq( Value_type( -1 ),            "-1" );
            check_eq( Value_type( int64_t( -1 ) ), "-1" );

            check_eq( Value_type( max_int64 ),             "9223372036854775807" );
            check_eq( Value_type( uint64_t( max_int64 ) ), "9223372036854775807" );

            check_eq( Value_type( max_uint64 ), "18446744073709551615" );
        }

        void test_ios_state_saved()
        {
            basic_ostringstream< Char_type > os;

            os << 0.123456789;

            Array_type arr;

            arr.push_back( 0.123456789 );

            write( arr, os );

            os << 0.123456789;

            assert_eq( os.str(), to_str( "0.123457"
                                         "[0.12345678900000000]"
                                         "0.123457" ) );
        }

        void check_remove_trailing_zeros( const double value, const String_type& expected_str_with, const String_type& expected_str_without )
        {
            check_eq( value, expected_str_with, 0 );
            check_eq( value, expected_str_without, remove_trailing_zeros );
        }

        void check_remove_trailing_zeros( const double value, const char* expected_str_with, const char* expected_str_without )
        {
            check_remove_trailing_zeros( value, to_str( expected_str_with ), to_str( expected_str_without ) );
        }

        void test_remove_trailing_zeros()
        {
#ifdef WIN32
            const String_type exp = to_str( "099" );
#else
            const String_type exp = to_str( "99" );
#endif
            check_remove_trailing_zeros( 0.0,           zero_str(),  to_str( "0.0" ) );
            check_remove_trailing_zeros( 1.2,           "1.2000000000000000",  "1.2" );
            check_remove_trailing_zeros( 0.123456789,   "0.12345678900000000",  "0.123456789" );
            check_remove_trailing_zeros( 1.2e-99,       to_str( "1.2000000000000000e-" ) + exp,  to_str( "1.2e-" ) + exp );
            check_remove_trailing_zeros( 1.23456789e99, to_str( "1.2345678900000001e+" ) + exp,  to_str( "1.23456789e+" ) + exp );
        }

        void run_tests()
        {
            test_empty_obj();
            test_obj_with_one_member();
            test_obj_with_two_members();
            test_obj_with_three_members();
            test_obj_with_one_empty_child_obj();
            test_obj_with_one_child_obj();
            test_obj_with_grandchild_obj();
            test_objs_with_bool_pairs();
            test_objs_with_int_pairs();
            test_objs_with_real_pairs();
            test_objs_with_null_pairs();
            test_empty_array();
            test_array_with_one_member();
            test_array_with_two_members();
            test_array_with_n_members();
            test_array_with_one_empty_child_array();
            test_array_with_one_child_array();
            test_array_with_grandchild_array();
            test_array_and_objs();
            test_obj_and_arrays();
            test_escape_chars();
            test_disabling_nonprintable_esc_chars();
            test_to_stream();
            test_values();
            test_uint64();
            test_ios_state_saved();
            test_remove_trailing_zeros();
        }
    };

#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING )
    void test_always_esc_nonascii()
    {
        if( iswprint( L'\x05DE' ) )
        {
            const wstring s( L"\x05DE\x05E9\x05EA\x05DE\x05E9" );

            wArray arr( 1, s );

            const wstring foo = arr[0].get_str();

            const wstring json_raw = write( arr );

            assert_eq( json_raw, L"[\"" + s + L"\"]" );

            const wstring json_escaped = write( arr, always_escape_nonascii );

            assert_eq( json_escaped, L"[\"\\u05DE\\u05E9\\u05EA\\u05DE\\u05E9\"]" );
        }
    }

    void test_wide_esc_u( wchar_t c, const wstring& result)
    {
        const wstring s( 1, c );

        wArray arr( 1, s );

        assert_eq( write( arr ), L"[\"\\u" + result + L"\"]" );
    }

    void test_wide_esc_u()
    {
        test_wide_esc_u( 0xABCD, L"ABCD" );
        test_wide_esc_u( 0xFFFF, L"FFFF" );
    }
#endif

    bool is_printable( char c )
    {
        const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c );

        return iswprint( unsigned_c ) != 0;
    }

#ifdef JSON_SPIRIT_VALUE_ENABLED
    void test_extended_ascii()
    {
        const string expeced_result( is_printable( '\xE4' ) ? "[\"\xE4\xF6\xFC\xDF\"]" : "[\"\\u00E4\\u00F6\\u00FC\\u00DF\"]" );

        assert_eq( write( Array( 1, "\xE4\xF6\xFC\xDF" ) ), expeced_result );
    }
#endif
}

void json_spirit::test_writer()
{
#ifdef JSON_SPIRIT_VALUE_ENABLED
    Test_runner< Config  >().run_tests();
    test_extended_ascii();
#endif
#ifdef JSON_SPIRIT_MVALUE_ENABLED
    Test_runner< mConfig >().run_tests();
#endif
#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING )
    Test_runner< wConfig  >().run_tests();
    test_wide_esc_u();
    test_always_esc_nonascii();
#endif
#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING )
    Test_runner< wmConfig >().run_tests();
#endif
}


text:
// Filename: matrix_indirect.cpp (part of MTL4)
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

using namespace std;

int main(int, char**)
{
    typedef mtl::dense2D<double> matrix;
    matrix A(5, 3);
    hessian_setup(A, 1.0);

    mtl::iset rows, cols;
    rows= 2, 0, 3; cols= 2, 1;

    cout << "rows = " << rows << ", cols = " << cols << "\n"
	 << "The sub-matrix A[{2, 0, 3}][{2, 1}] is\n" << A[rows][cols];

    mtl::mat::indirect<matrix> B(A[rows][cols]);
    cout << "B is\n" << B;

    return 0;
}


text:
/*
 * GraphBLAS Template Library (GBTL), Version 3.0
 *
 * Copyright 2020 Carnegie Mellon University, Battelle Memorial Institute, and
 * Authors.
 *
 * THIS MATERIAL WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY AN AGENCY OF
 * THE UNITED STATES GOVERNMENT.  NEITHER THE UNITED STATES GOVERNMENT NOR THE
 * UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNITED STATES DEPARTMENT OF
 * DEFENSE, NOR CARNEGIE MELLON UNIVERSITY, NOR BATTELLE, NOR ANY OF THEIR
 * EMPLOYEES, NOR ANY JURISDICTION OR ORGANIZATION THAT HAS COOPERATED IN THE
 * DEVELOPMENT OF THESE MATERIALS, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
 * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS,
 * OR USEFULNESS OR ANY INFORMATION, APPARATUS, PRODUCT, SOFTWARE, OR PROCESS
 * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED
 * RIGHTS.
 *
 * Released under a BSD-style license, please see LICENSE file or contact
 * permission@sei.cmu.edu for full terms.
 *
 * [DISTRIBUTION STATEMENT A] This material has been approved for public release
 * and unlimited distribution.  Please see Copyright notice for non-US
 * Government use and distribution.
 *
 * This Software includes and/or makes use of the following Third-Party Software
 * subject to its own license:
 *
 * 1. Boost Unit Test Framework
 * (https://www.boost.org/doc/libs/1_45_0/libs/test/doc/html/utf.html)
 * Copyright 2001 Boost software license, Gennadiy Rozental.
 *
 * DM20-0442
 */

#include <iostream>

#include <algorithms/maxflow.hpp>
#include <graphblas/graphblas.hpp>

using namespace grb;

#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE maxflow_test_suite

#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)

//****************************************************************************
BOOST_AUTO_TEST_CASE(maxflow_push_relabel_test)
{
    IndexArrayType i = {0, 0, 1, 2, 2, 3, 4, 4};
    IndexArrayType j = {1, 3, 2, 3, 5, 4, 1, 5};
    std::vector<double>       v = {15, 4, 12, 3, 7, 10, 5, 10};
    Matrix<double, DirectedMatrixTag> m1(6, 6);
    m1.build(i, j, v);

    //grb::print_matrix(std::cerr, m1, "\nGraph");
    auto result = algorithms::maxflow_push_relabel(m1, 0, 5);
    BOOST_CHECK_EQUAL(result, 14);
}

//****************************************************************************
BOOST_AUTO_TEST_CASE(maxflow_push_relabel_test2)
{
    //       s   1  2  3  4  5  6  t
    //  m1({{-, 10, 5,15, -, -, -, -},   // s = 0
    //      {-,  -, 4, -, 9,15, -, -},   // 1
    //      {-,  -, -, 4, -, 8, -, -},   // 2
    //      {-,  -, -, -, -, -,30, -},   // 3
    //      {-,  -, -, -, -,15, -,10},   // 4
    //      {-,  -, -, -, -, -,15,10},   // 5
    //      {-,  -, 6, -, -, -, -,10},   // 6
    //      {-,  -, -, -, -, -, -, -}}); // t = 7

    IndexArrayType i =      {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6};
    IndexArrayType j =      {1, 2, 3, 2, 4, 5, 3, 5, 6, 5, 7, 6, 7, 2, 7};
    std::vector<double> v = {10,5,15, 4, 9,15, 4, 8,30,15,10,15,10, 6,10};
    Matrix<double, DirectedMatrixTag> m1(8, 8);
    m1.build(i, j, v);

    //grb::print_matrix(std::cerr, m1, "\nGraph");
    auto result = algorithms::maxflow_push_relabel(m1, 0, 7);
    BOOST_CHECK_EQUAL(result, 28);
}

//****************************************************************************
BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test)
{
    IndexArrayType i = {0, 0, 1, 2, 2, 3, 4, 4};
    IndexArrayType j = {1, 3, 2, 3, 5, 4, 1, 5};
    std::vector<double>       v = {15, 4, 12, 3, 7, 10, 5, 10};
    Matrix<double, DirectedMatrixTag> m1(6, 6);
    m1.build(i, j, v);

    //grb::print_matrix(std::cerr, m1, "\nGraph");
    auto result = algorithms::maxflow_ford_fulk(m1, 0, 5);
    BOOST_CHECK_EQUAL(result, 14);
}

//****************************************************************************
BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test_counter_example)
{
    /*       2  2
     *      1--6--3
     *  2  /     / \  10
     *    /     /                               \
     *   0     /     5
     *    \   / 9   /
     *  9  \ /     /  2
     *      2-----4
     *         7
     */
    IndexArrayType      i = {0, 0, 1, 2, 2, 3, 4, 6};
    IndexArrayType      j = {1, 2, 6, 3, 4, 5, 5, 3};
    std::vector<double> v = {2, 9, 2, 9, 7,10, 2, 2};
    Matrix<double, DirectedMatrixTag> m1(7, 7);
    m1.build(i, j, v);

    //grb::print_matrix(std::cerr, m1, "\nGraph");
    auto result = algorithms::maxflow_ford_fulk(m1, 0, 5);
    BOOST_CHECK_EQUAL(result, 11);
}

//****************************************************************************
BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test2)
{
    //       s   1  2  3  4  5  6  t
    //  m1({{-, 10, 5,15, -, -, -, -},   // s = 0
    //      {-,  -, 4, -, 9,15, -, -},   // 1
    //      {-,  4, -, 4, -, 8, -, -},   // 2
    //      {-,  -, -, -, -, -,30, -},   // 3
    //      {-,  -, -, -, -,15, -,10},   // 4
    //      {-,  -, -, -, -, -,15,10},   // 5
    //      {-,  -, 6, -, -, -, -,10},   // 6
    //      {-,  -, -, -, -, -, -, -}}); // t = 7

    IndexArrayType i =      {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6};
    IndexArrayType j =      {1, 2, 3, 2, 4, 5, 3, 5, 6, 5, 7, 6, 7, 2, 7};
    std::vector<double> v = {10,5,15, 4, 9,15, 4, 8,30,15,10,15,10, 6,10};
    Matrix<double, DirectedMatrixTag> m1(8, 8);
    m1.build(i, j, v);

    //grb::print_matrix(std::cerr, m1, "\nGraph");
    auto result = algorithms::maxflow_ford_fulk(m1, 0, 7);
    BOOST_CHECK_EQUAL(result, 28);
}

//****************************************************************************
BOOST_AUTO_TEST_CASE(maxflow_ford_fulk_test2_bidirectional)
{
    //       s   1  2  3  4  5  6  t
    //  m1({{-, 10, 5,15, -, -, -, -},   // s = 0
    //      {-,  -, 4, -, 9,15, -, -},   // 1
    //      {-,  4, -, 4, -, 8, -, -},   // 2
    //      {-,  -, -, -, -, -,30, -},   // 3
    //      {-,  -, -, -, -,15, -,10},   // 4
    //      {-,  -, -, -, 5, -,15,10},   // 5
    //      {-,  -, 6, -, -, -, -,10},   // 6
    //      {-,  -, -, -, -, -, -, -}}); // t = 7

    IndexArrayType i =      {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 6, 6};
    IndexArrayType j =      {1, 2, 3, 2, 4, 5, 1, 3, 5, 6, 5, 7, 4, 6, 7, 2, 7};
    std::vector<double> v = {10,5,15, 4, 9,15, 4, 4, 8,30,15,10, 5,15,10, 6,10};
    Matrix<double, DirectedMatrixTag> m1(8, 8);
    m1.build(i, j, v);

    //grb::print_matrix(std::cerr, m1, "\nGraph");
    auto result = algorithms::maxflow_ford_fulk(m1, 0, 7);
    BOOST_CHECK_EQUAL(result, 30);
}

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: KIwabuchi/gbtl

max_issues_repo_name: KIwabuchi/gbtl

max_forks_repo_name: KIwabuchi/gbtl


text:
//==================================================================================================
/*!
  @file

  Defines the SSE specifications

  @copyright 2016 NumScale SAS

  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)

**/
//==================================================================================================
#ifndef BOOST_SIMD_ARCH_X86_SSE1_SPEC_HPP_INCLUDED
#define BOOST_SIMD_ARCH_X86_SSE1_SPEC_HPP_INCLUDED

#include <boost/simd/detail/predef.hpp>

#if !defined(BOOST_SIMD_DEFAULT_FAMILY)
  #if BOOST_HW_SIMD_X86 == BOOST_HW_SIMD_X86_SSE_VERSION
    #define BOOST_SIMD_DEFAULT_FAMILY ::boost::simd::sse_
    #define BOOST_SIMD_DEFAULT_SITE   ::boost::simd::sse1_
  #endif
#endif

#if BOOST_HW_SIMD_X86 >= BOOST_HW_SIMD_X86_SSE_VERSION
  #include <xmmintrin.h>
  #include <boost/simd/arch/x86/sse1/as_simd.hpp>
  #include <boost/simd/arch/x86/sse1/pack_traits.hpp>
#endif

#endif

max_stars_repo_name: SylvainCorlay/pythran

max_issues_repo_name: SylvainCorlay/pythran

max_forks_repo_name: SylvainCorlay/pythran


text:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <time.h>
#include <vector>
#include <cstdlib>
#include <unistd.h>
#include <ctime>
#include <boost/asio.hpp>
#include <sys/types.h>
//#include "writing.h"
//no longer required. ^^
#include "randomWordGen.h"
#include "md5.h"
#include "server1.h"

using namespace std;

int menu(){
	int choice;
	cout<<"CTU RockSat2019 Testing:\n\n"
		<<"1. Run MD5 Generator.\n"
		<<"2. Print Time.\n"
		<<"3. Random Number test\n"
		<<"4. Random number loop testing\n"
		<<"5. Read file list test\n"
		<<"6. Start server without being able to exit\n"
		<<"7. start server in background\n"
		<<"8. Random MD5 hash\n"
		<<"9. pass hash\n"
		<<"10. Exit.\n";
	cin >> choice;
//the menu will never be cleared while this is tested. system("CLS");
	return choice;
}

char* getTime(){
	return ctime(new time_t(time(0)));
	//COMMENT: gets the time from the system which will only be used for testing.
}

int main(){
	Random rand;
	Server start;
	string hash, md1, word, newValue;
	int input, r;
	do{
		input = menu();
		switch(input){
			case 1:
				//COMMENT: randomly sets the hash value, currently a work in progress.
  	        	md1 = md5("ssdd");
          		cout << "this should work:? " << md1 << endl;
			break;
			case 2:
				cout << "time: " << getTime();
			break;
			case 3:
				cout << "Random number: " << rand.returnNumber() << endl;
			break;
			case 4:
				cout << "Random number loop testing\n" << rand.getWordComb() << endl;
			break;
			case 5:
				//COMMENT: reads the random word
			//	word = rand.readFileTest();
				cout << "The random word is: " << word << endl;
			break;
			case 6:
				cout << "Starting server\n" << start.runServer() << endl;
			break;
			case 7: start.runServer();
			break;
			case 8:
     		   newValue = rand.readFileTest();
     		   cout << "MD5 random value: " << md5(newValue) << endl;
			break;
			case 9:
				hash = rand.readFileTest();
				start.setHash(hash);
				cout << "Succesful";
			break;
			case 10: cout <<"EXITING"<<endl;
			break;
			default: cout << "invalid choice"<<endl;
			break;
		}
	}while(input != 10);
	//COMMENT: tests.
	//cout << "\n MD5: " << hash;
	//system("PAUSE");
	//Print funciton for both ints and strings

	return 0;
}

max_stars_repo_path: C++/Combination Test 3/combMain.cpp

max_issues_repo_path: C++/Combination Test 3/combMain.cpp

max_forks_repo_path: C++/Combination Test 3/combMain.cpp